ホーム » .NET (ページ 2)
「.NET」カテゴリーアーカイブ
フォームへの描画
フォームに,左上から右下へグラデーションで表示する動作を幾つかの言語で書いてみた.
C#
//…
using System.Drawing.Drawing2D;
//…
namespace WinApCS
{
public partial class FormCS : Form
{
public FormCS()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
LinearGradientBrush brush = new LinearGradientBrush
(ClientRectangle,Color.Green,Color.White,LinearGradientMode.ForwardDiagonal);
e.Graphics.FillRectangle(brush,ClientRectangle);
}
protected override void OnResize(System.EventArgs e)
{
Invalidate();
}
}
}
VB
Imports System.Drawing.Drawing2D
Public Class FormVB
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim brush As New LinearGradientBrush
(ClientRectangle, Color.Blue, Color.White, LinearGradientMode.ForwardDiagonal)
e.Graphics.FillRectangle(brush, ClientRectangle)
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
Invalidate()
End Sub
End Class
J#
//…
import System.Drawing.Drawing2D.*;
//…
public class FormJS extends System.Windows.Forms.Form
{
//…
private void Form1_Paint(Object sender, PaintEventArgs e)
{
LinearGradientBrush brush = new LinearGradientBrush
(get_ClientRectangle(),Color.get_Red(),Color.get_White(),LinearGradientMode.ForwardDiagonal) ;
e.get_Graphics().FillRectangle(brush,get_ClientRectangle()) ;
}
protected void OnResize(System.EventArgs e)
{
this.Invalidate();
}
}
C++/CLI
//…
namespace WFmCpClr {
//…
using namespace System::Drawing::Drawing2D;
//…
public ref class FormVC : public System::Windows::Forms::Form
{
//…
private: System::Void FormVC_Paint
(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
LinearGradientBrush^ brush = gcnew LinearGradientBrush
(ClientRectangle,Color::Olive,Color::White,LinearGradientMode::ForwardDiagonal) ;
e->Graphics->FillRectangle(brush,ClientRectangle) ;
}
private: System::Void FormVC_Resize(System::Object^ sender, System::EventArgs^ e) {
Invalidate();
}
};
}