|
-
Apr 2nd, 2011, 06:39 PM
#1
Thread Starter
New Member
partial BackColor
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?
-
Apr 2nd, 2011, 07:41 PM
#2
Re: partial BackColor
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 3rd, 2011, 03:27 AM
#3
Thread Starter
New Member
Re: partial BackColor
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?
-
Apr 3rd, 2011, 07:54 AM
#4
Re: partial BackColor
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 3rd, 2011, 08:41 AM
#5
Thread Starter
New Member
Re: partial BackColor
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..
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 just cant understand why.. 
I searched the ms help, but didnt find there eather how to do this..
-
Apr 3rd, 2011, 08:52 AM
#6
Re: partial BackColor
it's because you called it in the Form1_Load event, which runs before the _paint event which will erase it
try:
vb Code:
Class1.fillRectangle(SystemColors.Control, Color.Red, 50, Me)
in a button_click event
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|