Hello everyone :)
So im makeing class, where i need to change BackColor for part of form..
What i meen is, i need to change forms BackColor, but not for all form, but for, example 20px from top..
is it posible?
Printable View
Hello everyone :)
So im makeing class, where i need to change BackColor for part of form..
What i meen is, i need to change forms BackColor, but not for all form, but for, example 20px from top..
is it posible?
try this:
vb Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.FillRectangle(New SolidBrush(SystemColors.Control), New Rectangle(0, 0, Me.ClientRectangle.Width, 20)) e.Graphics.FillRectangle(Brushes.Red, New Rectangle(0, 20, Me.ClientRectangle.Width, Me.ClientRectangle.Height)) End Sub
for a fade in effect:
vb Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Using Brush As New LinearGradientBrush(Me.ClientRectangle, SystemColors.Control, Color.Red, Drawing2D.LinearGradientMode.Vertical) Dim b = New ColorBlend(4) b.Colors = New Color() {SystemColors.Control, _ SystemColors.Control, _ Color.Red} b.Positions = New Single() {0.0F, 0.1F, 1.0F} Brush.InterpolationColors = b e.Graphics.FillRectangle(Brush, Me.ClientRectangle) End Using End Sub
Okey, that works, but how about this?
I have external file (dll, or just other class added), in i make a sub or function, where i set the draw function..
For example, class1.FillRectangle(sizeX, sizeY, startX, startY, Me)
where sizeX, sizeY, startX, startY is the values to set, and Me, go's for form1..
Is this posible?
try something like this:
vb Code:
Public Class Form1 Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Class1.fillRectangle(SystemColors.Control, Color.Red, 20, Me) End Sub End Class
vb Code:
Public Class Class1 Public Shared Sub fillRectangle(ByVal color1 As Color, ByVal color2 As Color, ByVal splitPoint As Integer, ByVal frm As Form) Dim gr As Graphics = frm.CreateGraphics gr.FillRectangle(New SolidBrush(color1), New Rectangle(0, 0, frm.ClientRectangle.Width, splitPoint)) gr.FillRectangle(New SolidBrush(color2), New Rectangle(0, splitPoint, frm.ClientRectangle.Width, frm.ClientRectangle.Height)) End Sub End Class
ok, so, i wrote exactly as you, but it didnt worked
Code:Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Class1.fillRectangle(SystemColors.Control, Color.Red, 50, Me)
End Sub
End Class
Code:Public Class Class1
Public Shared Sub fillRectangle(ByVal color1 As Color, ByVal color2 As Color, ByVal splitPoint As Integer, ByVal frm As Form)
Dim gr As Graphics = frm.CreateGraphics
gr.FillRectangle(New SolidBrush(color1), New Rectangle(0, 0, frm.ClientRectangle.Width, splitPoint))
gr.FillRectangle(New SolidBrush(color2), New Rectangle(0, splitPoint, frm.ClientRectangle.Width, frm.ClientRectangle.Height))
End Sub
End Class
I tried to put it in actual form, that needs to change the forecolor, but no luck there too..
i just cant understand why.. :(Code:Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Class1.fillRectangle(SystemColors.Control, Color.Red, 50, Me)
Dim gr As Graphics = Me.CreateGraphics
gr.FillRectangle(New SolidBrush(SystemColors.Control), New Rectangle(0, 0, Me.ClientRectangle.Width, 20))
End Sub
End Class
I searched the ms help, but didnt find there eather how to do this..
it's because you called it in the Form1_Load event, which runs before the _paint event which will erase it
try:
in a button_click eventvb Code:
Class1.fillRectangle(SystemColors.Control, Color.Red, 50, Me)