C\#색상 그 라 데 이 션 창 컨트롤 상세 설명 실현
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
2.코드 구현
private Color Color1 = Color.Gray; //
private Color Color2 = Color.White ; //
private float changeAngle = 0f; //
3.창 그리 기 함수
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle grounRect = new Rectangle(0, 0, this.Width, this.Height);
System.Drawing.Drawing2D.LinearGradientBrush backGround = new System.Drawing.Drawing2D.LinearGradientBrush(grounRect, Color1, Color2, changeAngle);
g.FillRectangle(backGround, grounRect);
backGround.Dispose();
}
추가:WPS 에서 LinearGradientBrush 선형 그 라 데 이 션 사용1.색상 배열
주:
(1)열 배열 의 시작 좌 표 는(0,0.5)종료 좌 표 는(1,0.5)이다.
(2)그 중에서 offset 이 놓 인 위치 매개 변 수 는 계산 해 야 합 니 다.
예 를 들 어 모두 네 개의 색깔 이 있 는데 그것 이 바로 1/4=0.25 이다.1 개 색깔 0.25,1 개 색깔 0.25,2 개 색깔 0.25=0.5,3 개 0.75,4 개 색깔 1
public MainWindow()
{
InitializeComponent();
// Border ,
Border bord1 = new Border();
bord1.Width = bord1.Height=200;
indext.Children.Add(bord1);
//
LinearGradientBrush brush = new LinearGradientBrush();//
// (0,0.5) (1,0.5)
brush.StartPoint = new Point(0, 0.5);//
brush.EndPoint=new Point(1,0.5);//
brush.GradientStops.Add(new GradientStop(color: Colors.Pink,offset:0.25));
//GradientStops
//GradientStop color , offset
brush.GradientStops.Add(new GradientStop(color: Colors.IndianRed,offset:0.50));
brush.GradientStops.Add(new GradientStop(color: Colors.LightSteelBlue,offset:0.75));
brush.GradientStops.Add(new GradientStop(color: Colors.LightSeaGreen,offset:1.0));
bord1.Background = brush;
// Border
}
2.색상 줄 정렬주:
줄 을 배열 할 때 시작 위치 와 종료 위 치 는 위치 만 바 뀌 었 을 뿐이다.
열 배열 의 시작 좌 표 는(0.5,0)종료 좌 표 는(0.5,1)이다.
public MainWindow()
{
InitializeComponent();
Border bord1 = new Border();
bord1.Width = bord1.Height=200;
indext.Children.Add(bord1);
LinearGradientBrush brush = new LinearGradientBrush();
//
brush.StartPoint = new Point(0.5,0);
brush.EndPoint=new Point(0.5,1);
brush.GradientStops.Add(new GradientStop(color: Colors.Pink,offset:0.25));
brush.GradientStops.Add(new GradientStop(color: Colors.IndianRed,offset:0.50));
brush.GradientStops.Add(new GradientStop(color: Colors.LightSteelBlue,offset:0.75));
brush.GradientStops.Add(new GradientStop(color: Colors.LightSeaGreen,offset:1.0));
bord1.Background = brush;
}
3.왼쪽 위 에서 오른쪽 아래 까지 비스듬히 배열주:
비스듬히 배열 하려 면 시작 위치 와 종료 위 치 는 계산 을 설정 하지 않 고 기본 배열 은 offset 의 위치 크기 만 계산 해 야 합 니 다.
public MainWindow()
{
InitializeComponent();
Border bord1 = new Border();
bord1.Width = bord1.Height=200;
indext.Children.Add(bord1);
LinearGradientBrush brush = new LinearGradientBrush();
brush.GradientStops.Add(new GradientStop(color: Colors.Pink,offset:0.25));
brush.GradientStops.Add(new GradientStop(color: Colors.IndianRed,offset:0.50));
brush.GradientStops.Add(new GradientStop(color: Colors.LightSteelBlue,offset:0.75));
brush.GradientStops.Add(new GradientStop(color: Colors.LightSeaGreen,offset:1.0));
bord1.Background = brush;
}
이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.만약 잘못 이 있 거나 완전히 고려 하지 않 은 부분 이 있다 면 아낌없이 가르침 을 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.