3
A
答えて
5
一つの方法は、直接フォームのBackgroundImage
として画像を使用することです。
あなたはこのproceduarally(より柔軟な)を達成したい場合は、手動OnPaintBackground
を使用して、フォームの背景を描くことができます。
protected override void OnPaintBackground(PaintEventArgs e)
{
using (var brush = new LinearGradientBrush
(DisplayRectangle, Color.Black, Color.DarkGray, LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(brush, DisplayRectangle);
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
Invalidate(); // Force repainting on resize
}
結果:
2
使用しOnPaint event
を使用することができますwinform
の一部の変更を行うことができます。詳細については、指定されたリンクを確認してください。
としてこれを行うにはLinearGradientBrush
を使用します。別の方法が使用され
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
' Declare a variable of type Graphics named formGraphics.
' Assign the address (reference) of this forms Graphics object
' to the formGraphics variable.
Dim formGraphics As Graphics = e.Graphics
' Declare a variable of type LinearGradientBrush named gradientBrush.
' Use a LinearGradientBrush constructor to create a new LinearGradientBrush object.
' Assign the address (reference) of the new object
' to the gradientBrush variable.
Dim gradientBrush As New LinearGradientBrush(New Point(0, 0), New Point(Width, 0), Color.White, Color.DarkMagenta)
' Here are two more examples that create different gradients.
' Comment the Dim statement immediately above and uncomment one of these
' Dim statements to see how varying the two colors changes the gradient result.
' Dim gradientBrush As New LinearGradientBrush(New Point(0, 0), New Point(Width, 0), Color.Chartreuse, Color.SteelBlue)
' Dim gradientBrush As New LinearGradientBrush(New Point(0, 0), New Point(Width, 0), Color.White, Color.SteelBlue)
formGraphics.FillRectangle(gradientBrush, ClientRectangle)
End Sub
:
のOnPaint過負荷の/*リニアグラデーションブラシ*/
を取るLinearGradientBrush brush = new LinearGradientBrush(rect, Color.Orange, Color.Orchid, LinearGradientMode.ForwardDiagonal);
コードスニペットOnPaintBackground
イベントと使用LinearGradientBrush
ref:MSDN
protected override void OnPaintBackground(PaintEventArgs e) {
Rectangle rc = new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height);
using (LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Red, Color.Blue, 45F)) {
e.Graphics.FillRectangle(brush, rc);
}
参考:Resize
関連情報ここ
How to Add a Gradient Background to a Win Form with VB.NET & VB2005
Windows Forms 2.0-Draw Beautiful Gradient Backdrops
Set Gradient/Shaded Background to Windows form using c#
チェック: this.Invalidate()
- これはSOまた、スレッド
Create a Gradient background on your Forms or Controls
チェック.. Transparent control backgrounds on a VB.NET gradient filled form?
関連する問題
- 1. コンソールアプリケーションの背景色と前景色を設定しますか?
- 2. angular2 ngClassフォームの背景色を設定していません
- 3. 背景色を設定
- 4. EPPlus設定の背景色
- 5. 色の代わりに背景色を設定するには?
- 6. グラフの背景色を設定する
- 7. UIVIewの背景色を設定する
- 8. JPanelの背景色を設定する
- 9. ツールボタンの背景色を設定する
- 10. アクティビティの背景色を設定する
- 11. ルートウィンドウの背景色を設定する
- 12. Pyside:QScrollAreaの背景色を設定する
- 13. 列の背景色を設定する
- 14. 背景色のサイズを設定する
- 15. ウェブマークアップ、背景色をベースに設定
- 16. ap要素の背景色を設定すると、上の画像の背景色も設定されます
- 17. angular2設定した背景色
- 18. SSRS HTML背景色を設定する
- 19. JavaFX:TextFlowで背景色を設定する
- 20. Android - SimpleCursorAdapter.ViewBinder - 背景色を設定する
- 21. リストビューで背景色を設定する
- 22. 背景色が設定されていないと、Androidは親ビューの背景色を取得します
- 23. 設定tableGrobの背景色をR
- 24. ページの背景色を設定
- 25. Design BottomNavigationView - コードの背景色を設定
- 26. 設定の背景色ngのリピートを使用した場合
- 27. XSLTセットテーブルの背景色を設定した場合
- 28. レイアウトビューの背景色をAndroidのグラデーションに設定しますか?
- 29. Androidステータスバーで背景色を半透明色に設定
- 30. Androidツールバーで背景色を半透明色に設定
これは私にとってはうまくいくが、ここで私が直面する問題は左下と右下に2つのボタンがあることだ。このフォームを最大化すると、両方のボタンが中央に配置されます。両方のボタンの固定が設定されていますが、フォームを最大化するときに問題が発生します – Rupesh
アンカーがそれぞれ「下、左」および「下、右」に設定されていることを確認してください。 – Ani
私の間違い。私はちょうど数分前にボタンの位置を逆転させましたが、アンカーをもう一度設定するのを忘れました。今すぐうまくいく。どうもありがとうございます – Rupesh