颜色基本设置

普通颜色设置可以直接选取系统定义的颜色。高级设置采用RGB颜色。

Color myColor = Color.FromArgb(23,56,78);

每个数字均必须是从 0 到 255 之间的一个整数,分别表示红、绿、蓝三种原色。其中 0 表示没有该颜色,而 255 则为所指定颜色的完整饱和度。如Color.FromArgb(0,255,0)表示绿色,Color.FromArgb(255,255,0)表示黄色,Color.FromArgb(0,0,0) 呈现为黑色,而 Color.FromArgb(255,255,255) 呈现为白色。

还可以设置透明度,例如:Color myColor= Color.FromArgb(127, 23, 56, 78);

127表示50%的透明度,255表示完全不透明。

  1. 选择颜色

以下程序可以从调色板选择一个颜色,在textBox上面显示。

private void button1_Click(object sender, Sy e)

{

ColorDialog MyDialog = new ColorDialog();

MyDialog.AllowFullOpen = false ;

MyDialog.ShowHelp = true ;

MyDialog.Color = ;

if () == DialogRe)

= MyDialog.Color;

}

2.产生窗体选择颜色

本程序在一个菜单里调用选择程序,产生一个动态的窗体,选择颜色后返回主程序,刷新原来的页面。

Form form1;

bool Cform=true;

//颜色设置

private void menuItem31_Click(object sender, Sy e)

{

while (Cform)

{

CreateColorForm();

Tuli1();

DisLine();

}

Cform=true;

}

//产生颜色输入窗体

private void CreateColorForm()

{

int i;

form1=new Form();

Button [] ColorButton = new Button [myPloys.mark];

Label [] ColorLabel = new Label [myPloys.mark];

Button button0 = new Button ();

;

form1.Height=130+myPloys.mark*30;

= "等值线颜色输入";

= FormBorderS;

= false;

= FormS;

bu = "退出";

bu;

bu Point(25,50+myPloys.mark*30);

(button0);

= button0;

for (i=0;i<myPloys.mark;i++)

{

ColorLabel[i]=new Label();

ColorLabel[i].Location=(Point)new Point(30,30+30*i);

ColorLabel[i].Width=30;

ColorLabel[i].Text=myPloys.marks1[i].ToString();

(ColorLabel[i]);

ColorButton[i]=new Button();

ColorButton[i].BackColor=cColor[i];

ColorButton[i].Location=(Point)new Point(60,26+30*i);

ColorButton[i].Width=30;

switch (i)

{

case 0:

ColorButton[i].Click += new Sy(ColorButton0_Click);

break;

case 1:

ColorButton[i].Click += new Sy(ColorButton1_Click);

break;

case 2:

ColorButton[i].Click += new Sy(ColorButton2_Click);

break;

case 3:

ColorButton[i].Click += new Sy(ColorButton3_Click);

break;

case 4:

ColorButton[i].Click += new Sy(ColorButton4_Click);

break;

case 5:

ColorButton[i].Click += new Sy(ColorButton5_Click);

break;

case 6:

ColorButton[i].Click += new Sy(ColorButton6_Click);

break;

case 7:

ColorButton[i].Click += new Sy(ColorButton7_Click);

break;

case 8:

ColorButton[i].Click += new Sy(ColorButton8_Click);

break;

case 9:

ColorButton[i].Click += new Sy(ColorButton9_Click);

break;

case 10:

ColorButton[i].Click += new Sy(ColorButton10_Click);

break;

default:

break;

}

(ColorButton[i]);

}

bu += new Sy(button0_Click);

();

}

private void ColorSelect(int si)

{

ColorDialog MyDialog = new ColorDialog();

MyDialog.AllowFullOpen = true ;

MyDialog.ShowHelp = true ;

MyDialog.Color = cColor[si] ;

if () == DialogRe)

cColor[si] = MyDialog.Color;

();

}

private void ColorButton0_Click(object sender, Sy e)

{ ColorSelect(0); }

private void ColorButton1_Click(object sender, Sy e)

{ ColorSelect(1); }

private void ColorButton2_Click(object sender, Sy e)

{ ColorSelect(2); }

private void ColorButton3_Click(object sender, Sy e)

{ ColorSelect(3); }

private void ColorButton4_Click(object sender, Sy e)

{ ColorSelect(4); }

private void ColorButton5_Click(object sender, Sy e)

{ ColorSelect(5); }

private void ColorButton6_Click(object sender, Sy e)

{ ColorSelect(6); }

private void ColorButton7_Click(object sender, Sy e)

{ ColorSelect(7); }

private void ColorButton8_Click(object sender, Sy e)

{ ColorSelect(8); }

private void ColorButton9_Click(object sender, Sy e)

{ ColorSelect(9); }

private void ColorButton10_Click(object sender, Sy e)

{ ColorSelect(10); }

private void button0_Click(object sender, Sy e)

{

Cform=false;

();

}

Font和标注

  1. 基本操作

可以在指定的点开始写字,也可以在一个范围(如矩形)内写字。

Font myFont = new Font("Times New Roman", 14);

Graphics g = ();

Pen myPen=new Pen);

Sy myBrush=new SolidBru);

g.DrawRectangle(myPen,10, 10, 100, 200);

g.DrawString("Look at this text!", myFont, myBrush, new RectangleF(10, 10, 100, 200));

g.DrawString("Look at this text!", myFont, myBrush, 10, 250);

2.画点和标注

Sy myPen;

myPen = new Sy);

Sy formGraphics = ();

Sy drawBrush = new Sy);

Sy drawFont = new Sy("Arial", 8);

string drawString = "201";

float x = 100.0f;

float y = 100.0f;

(myPen, x, y,4,4);

(drawString, drawFont, drawBrush, x, y);

myPen.Dispose();

drawFont.Dispose();

drawBru();

();

3.Font定义

public Font(

FontFamily family,

float emSize,

FontStyle style,

GraphicsUnit unit

);

以下的例子可以改变字体,大小、字形、单位,还可以设置成垂直。

// Font myFont = new Font("Times New Roman",14,Fon);

Font myFont = new Font("隶书",34,Fon);

Graphics g = ();

Sy myBrush=new SolidBru);

Sy drawFormat = new Sy );

g.DrawString("Hello!你好", myFont, myBrush, 10, 10,drawFormat);

根据给定点找到实际标注点

//根据给定点,找到实际标注点,使得以画出的字符串以给定点为中心

public PointF StringCenter(string s1,float sz,PointF p0)

{

PointF p1=new PointF();

float x0=0;

float height=0;

float width=StringWidth(s1,sz,ref x0,ref height);

;

;

return p1;

}

1.《如何在C中改变输出的颜色 如何改变瞳孔颜色》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。

2.《如何在C中改变输出的颜色 如何改变瞳孔颜色》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。

3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/keji/3301960.html