I am creating a game similar to Lunar Lander and am attempting to make a simple randomly generated terrain each time the game loads. I am currently generating random points and drawing a curve through these points and the two bottom corners of the canvas.
However for some reason the peak of the curve is being mirrored to the top of the canvas as well as the bottom.
Here is the code:
Public Class Form1
Dim xpoint1 As Single
Dim ypoint1 As Single
Dim xpoint2 As Single
Dim ypoint2 As Single
Dim xpoint3 As Single
Dim ypoint3 As Single
Dim xpoint4 As Single
Dim ypoint4 As Single
Dim isTerrainDrawn As Integer = 0
Private Sub generateRandomTerrain()
Dim terrainBrush As New SolidBrush(Color.Gray)
Dim terrainDraw As Graphics = Me.CreateGraphics
Dim rand As New Random
'Generate Different Points for Terrain
xpoint1 = 40 * rand.Next(0, 10)
ypoint1 = 40 * rand.Next(0, 10)
xpoint2 = 40 * rand.Next(10, 20)
ypoint2 = 40 * rand.Next(10, 20)
xpoint3 = 40 * rand.Next(20, 30)
ypoint3 = 40 * rand.Next(20, 30)
xpoint4 = 40 * rand.Next(0, 10)
ypoint4 = 40 * rand.Next(0, 10)
'Generate Points to Draw
Dim terrain() As Point = {New Point(0, Me.Size.Height), New Point(0, Me.Size.Height - 100), New Point((Me.Size.Width * 0.2) + Me.xpoint1, Me.Size.Height - Me.ypoint1 - 100), New Point((Me.Size.Width * 0.45) + Me.xpoint2, Me.Size.Height - Me.ypoint2 - 100), New Point((Me.Size.Width * 0.75) - Me.xpoint3, Me.Size.Height - 100 - Me.ypoint3), New Point((Me.Size.Width * 0.8) + (Me.Size.Width * 0.05) - Me.xpoint4, Me.Size.Height - Me.ypoint4 - 100), New Point(Me.Size.Width, Me.Size.Height - 100), New Point(Me.Size.Width, Me.Size.Height)}
'Is Terrain Drawn-Clear
If Me.isTerrainDrawn = 1 Then
terrainDraw.Clear(Color.Transparent)
Me.isTerrainDrawn = 0
End If
'Draw Terrain Aspects
terrainDraw.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
terrainDraw.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
terrainDraw.CompositingMode = Drawing2D.CompositingMode.SourceOver
'Draw Terrain
terrainDraw.FillClosedCurve(terrainBrush, terrain)
'Set Terrain to Drawn
Me.isTerrainDrawn = 1
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
generateRandomTerrain()
End Sub
End Class
Any help is much appreciated.
Related
In preparation for my Fall upcoming Adobe Illustrator class, where students always curse while learning the Pen tool and how to draw Bézier curves, I thought I'd provide them with some "theoretical foundation" outside of Illustrator. So far, I'm able to demonstrate the workings of a curve through four points described by x and y coordinates entered in a separate text boxes (see attached screen capture). My question, how can I "transform" this static demonstration into an interactive one, by allowing the students to "select" control points (shown in blue) and move them around the PictureBox? That's not a simple problem. Any pointers would be appreciated.
Here is my source code so far:
Public Class Form1
Dim Point1_X, Point1_Y, Point2_X, Point2_Y, Point3_X, Point3_Y, Point4_X, Point4_Y As Integer
Dim LignesDeDirection As Boolean
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LignesDeDirection = False
Point1_X = 100
Point1_Y = 100
Point2_X = 200
Point2_Y = 200
Point3_X = 50
Point3_Y = 250
Point4_X = 400
Point4_Y = 400
tbPoint1_X.Text = Point1_X
tbPoint1_Y.Text = Point1_Y
tbPoint2_X.Text = Point2_X
tbPoint2_Y.Text = Point2_Y
tbPoint3_X.Text = Point3_X
tbPoint3_Y.Text = Point3_Y
tbPoint4_X.Text = Point4_X
tbPoint4_Y.Text = Point4_Y
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.Clear(Color.LightGray)
Dim FondBlanc As New SolidBrush(Color.White)
e.Graphics.FillRectangle(FondBlanc, 0, 0, PictureBox1.Width, PictureBox1.Height)
Dim blackPen = New Pen(Color.FromArgb(128, 128, 128), 1)
Dim blackPen2pix = New Pen(Color.FromArgb(64, 64, 64), 2)
Dim EllipsePen = New Pen(Color.FromArgb(0, 128, 255), 3)
Dim blackPen3 = New Pen(Color.Black, 5.0F)
Dim blackPen2 = New Pen(Color.FromArgb(164, 164, 164), 1)
Dim CouleurPoint As New SolidBrush(Color.Magenta)
Dim CouleurControl As New SolidBrush(Color.Blue)
Dim Color2 = New Pen(Color.FromArgb(128, 128, 128), 1)
Dim PenBleu As New Pen(Color.Black, 2.0F)
PenBleu.EndCap = System.Drawing.Drawing2D.LineCap.Flat 'PenBleu.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor
PenBleu.CustomEndCap = New System.Drawing.Drawing2D.AdjustableArrowCap(8, 8)
Dim point1 As New Point(Point1_X, Point1_Y)
Dim point2 As New Point(Point2_X, Point2_Y)
Dim point3 As New Point(Point3_X, Point3_Y)
Dim point4 As New Point(Point4_X, Point4_Y)
e.Graphics.FillEllipse(CouleurPoint, Point1_X - 5, Point1_Y - 5, 10, 10)
e.Graphics.FillEllipse(CouleurControl, Point2_X - 5, Point2_Y - 5, 10, 10)
e.Graphics.FillEllipse(CouleurControl, Point3_X - 5, Point3_Y - 5, 10, 10)
e.Graphics.FillEllipse(CouleurPoint, Point4_X - 5, Point4_Y - 5, 10, 10)
Dim PenDashMagenta As New Pen(Color.Magenta, 1.5F)
PenDashMagenta.DashStyle = Drawing2D.DashStyle.Dash
Dim PenRéférence As New Pen(Color.ForestGreen, 1.0F)
If cbDirectionLines.Checked = True Then
LignesDeDirection = True
e.Graphics.DrawLine(PenRéférence, Point1_X, Point1_Y, Point2_X, Point2_Y)
e.Graphics.DrawLine(PenRéférence, Point3_X, Point3_Y, Point4_X, Point4_Y)
Else
LignesDeDirection = False
End If
e.Graphics.DrawEllipse(PenDashMagenta, Point1_X - 40, Point1_Y - 40, 80, 80)
e.Graphics.DrawEllipse(PenDashMagenta, Point4_X - 40, Point4_Y - 40, 80, 80)
e.Graphics.DrawBezier(PenBleu, point1, point2, point3, point4)
End Sub
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Point1_X = tbPoint1_X.Text
Point1_Y = tbPoint1_Y.Text
Point2_X = tbPoint2_X.Text
Point2_Y = tbPoint2_Y.Text
Point3_X = tbPoint3_X.Text
Point3_Y = tbPoint3_Y.Text
Point4_X = tbPoint4_X.Text
Point4_Y = tbPoint4_Y.Text
PictureBox1.Invalidate()
End Sub
End Class
I'm designing a hexagon grid and I need to be able to name each hexagon, so I can refer to them later. Below is my class, it generates the hexagon grid, and I've labeled the code throughout so you can understand what's happening.
I've been searching for a while now reading a lot about Graphics, but I can't get a working design with the answers I've seen offered. Perhaps, I'm going about this wrong by using Graphics, but my plan is to be able to click on each hexagon and do something with it.
Note: If you see a way to improve my code let me know. It's appreciated!
' Generate Hexagon Grid
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
' Hexagon Grid Parameters
Dim HexagonRadius As Integer = 20 ' Fix "Position Hexagon Grid Columns" Before Changing Hexagon Radius
Dim GridSize As Integer = 10
' Generate Hexagon Grid
Dim HexagonX As Integer = HexagonRadius
Dim HexagonY As Integer = HexagonRadius
For i As Integer = 1 To GridSize
For j As Integer = 1 To GridSize
' Hexagon Vertex Coordinates
Dim point1 As New Point((HexagonX - HexagonRadius), (HexagonY))
Dim point2 As New Point((HexagonX - (HexagonRadius / 2)), (HexagonY + ((HexagonRadius / 2) * Math.Sqrt(3))))
Dim point3 As New Point((HexagonX + (HexagonRadius / 2)), (HexagonY + ((HexagonRadius / 2) * Math.Sqrt(3))))
Dim point4 As New Point((HexagonX + HexagonRadius), (HexagonY))
Dim point5 As New Point((HexagonX + (HexagonRadius / 2)), (HexagonY - ((HexagonRadius / 2) * Math.Sqrt(3))))
Dim point6 As New Point((HexagonX - (HexagonRadius / 2)), (HexagonY - ((HexagonRadius / 2) * Math.Sqrt(3))))
Dim hexagonPoints As Point() = {point1, point2, point3, point4, point5, point6}
' Create Hexagon
e.Graphics.FillPolygon(Brushes.Green, hexagonPoints)
' Hexagon Outline
e.Graphics.DrawLine(Pens.Black, point1, point2)
e.Graphics.DrawLine(Pens.Black, point2, point3)
e.Graphics.DrawLine(Pens.Black, point3, point4)
e.Graphics.DrawLine(Pens.Black, point4, point5)
e.Graphics.DrawLine(Pens.Black, point5, point6)
e.Graphics.DrawLine(Pens.Black, point6, point1)
' Position Hexagon Grid Columns
HexagonY += 34 ' Specific to Hexagon Radius: 20
Next
If i Mod 2 > 0 Then
HexagonY = 36.75 ' Specific to Hexagon Radius: 20
Else
HexagonY = 20 ' Specific to Hexagon Radius: 20
End If
HexagonX += 30 ' Specific to Hexagon Radius: 20
Next
End Sub
You'll need to create some Hexagon class with it's coordinates and (maybe name, if really needed). And save them to some suitable collection (2-dimensional array maybe?)
This should happen somewhere outside your Paint event and might be recalculated on grid SizeChanged event.
Inside your Paint event you'll just iterate throught existing collection and render according to pre-computed coordinates.
OnClick event will loop throught the same collection to find specific Hexagon for updating (changing background color for example) and forcing form to repaint to take effect.
For large rendering you should consider rendering to bitmap first and drawing that final bitmap to e.Graphics for faster work. Your bitmap could be cached as well to speed up even more.
EDIT: Code sample added
Turn Option Strict On in your project properties to avoid many problems in your code that you're not aware of.
Public Class frmTest
Private Const HexagonRadius As Integer = 20
Private Const GridSize As Integer = 10
Private fHexagons As New List(Of Hexagon)
Private fCache As Bitmap
Private fGraphics As Graphics
Private Sub ResetHexagons() 'Call when some parameter changes (Radius/GridSize)
fHexagons.Clear()
Invalidate()
End Sub
Private Function EnsureHexagons() As List(Of Hexagon)
Dim X, Y As Single, xi, yi As Integer
If fHexagons.Count = 0 Then
X = HexagonRadius : Y = HexagonRadius
For xi = 1 To GridSize
For yi = 1 To GridSize
fHexagons.Add(New Hexagon(HexagonRadius, X, Y))
Y += 34
Next
'Do your math to get theese values from HexagonRadius value
If xi Mod 2 > 0 Then
Y = 36.75
Else
Y = 20
End If
X += 30
Next
fCache?.Dispose()
fGraphics?.Dispose()
fCache = New Bitmap(GridSize * HexagonRadius * 2, GridSize * HexagonRadius * 2)
fGraphics = Graphics.FromImage(fCache)
For Each H As Hexagon In fHexagons
H.Render(fGraphics)
Next
End If
Return fHexagons
End Function
Private Sub frmTest_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
EnsureHexagons()
e.Graphics.DrawImageUnscaled(fCache, Point.Empty)
End Sub
Private Sub frmTest_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
Dim H As Hexagon = EnsureHexagons.FirstOrDefault(Function(X) X.Contains(e.Location))
If H IsNot Nothing Then
H.Checked = Not H.Checked
H.Render(fGraphics) 'Update cache without repainting all
Invalidate()
End If
End Sub
End Class
Public Class Hexagon
Public ReadOnly Radius, X, Y As Single
Public ReadOnly Points() As PointF
Public Property Checked As Boolean
Public Sub New(Radius As Single, X As Single, Y As Single)
Me.Radius = Radius : Me.X = X : Me.Y = Y
Points = {New PointF((X - Radius), (Y)),
New PointF((X - (Radius / 2)), CSng(Y + ((Radius / 2) * Math.Sqrt(3)))),
New PointF((X + (Radius / 2)), CSng(Y + ((Radius / 2) * Math.Sqrt(3)))),
New PointF((X + Radius), (Y)),
New PointF((X + (Radius / 2)), CSng(Y - ((Radius / 2) * Math.Sqrt(3)))),
New PointF((X - (Radius / 2)), CSng(Y - ((Radius / 2) * Math.Sqrt(3.0!))))}
End Sub
Public Sub Render(G As Graphics)
' Create Hexagon
G.FillPolygon(If(Checked, Brushes.Blue, Brushes.Green), Points)
' Hexagon Outline
For i As Integer = 0 To Points.Length - 1
G.DrawLine(Pens.Black, Points(i), Points((i + 1) Mod Points.Length))
Next
End Sub
Public Function Contains(P As Point) As Boolean
'Do your math here, this is just simplified estimation
Return X - Radius <= P.X AndAlso P.X <= X + Radius AndAlso Y - Radius <= P.Y AndAlso P.Y <= Y + Radius
End Function
End Class
I have equations that I need to plot in VB.Net. I found this library, MATH.Net. It has a lot of examples with C#.
Can I use this library to plot polynomial functions in VB.NET?
If so, then how? As I couldn't find any examples on the Internet.
If not, then can anyone please guide me on how to plot polynomials on a graph in VB.Net?
I'm using Microsoft Visual Studio 2010, and have very little experience in visual basic (I have made so simple applications like calculators, etc).
Generate some data points and add them to a series on the chart.
For example,
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Function Polynom(x As Double) As Double
Return Math.Pow(x, 3) + Math.Pow(x, 2) + x
End Function
Function Polynom2(x As Double) As Double
Return 3 * Math.Pow(x, 2) + 2 * x + 1
End Function
Sub CreateChart()
Dim xMin = -2.0
Dim xMax = 2.0
Dim nPoints = 21
Dim xInc = (xMax - xMin) / (nPoints - 1)
Dim c As New Chart
c.Size = New Size(Me.Width * 0.9, Me.Height * 0.9)
c.Series.Clear()
Dim ca As New ChartArea With {.Name = "ChartArea1"}
ca.AxisX.Title = "variable"
ca.AxisY.Title = "dependent variable"
ca.AxisX.Minimum = xMin
ca.AxisX.Maximum = xMax
c.ChartAreas.Add(ca)
Dim s1 As New Series
s1.Name = "Polynomial"
s1.MarkerStyle = MarkerStyle.Circle
Dim s2 As New Series With {
.Name = "Derivative",
.MarkerStyle = MarkerStyle.Diamond,
.ChartType = SeriesChartType.Line
}
For i = 0 To nPoints - 1
Dim x = xMin + i * xInc
s1.Points.AddXY(x, Polynom(x))
s2.Points.AddXY(x, Polynom2(x))
Next
c.Series.Add(s1)
c.Series.Add(s2)
c.Series("Polynomial").ChartType = SeriesChartType.Line
Dim lgnd As New Legend With {.Name = "Legend"}
c.Legends.Add(lgnd)
lgnd.DockedToChartArea = "ChartArea1"
lgnd.Docking = Docking.Top Or Docking.Left
s1.Legend = "Legend"
s2.Legend = "Legend"
Me.Controls.Add(c)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Size = New Size(640, 480)
Me.Text = "Simple polynomial plot"
CreateChart()
End Sub
End Class
generates
I am making a lunar lander game, and want the spaceship to rotate when the left and right arrow keys are pressed.
I know how to move an image using a picture box and the keydown event, but there isn't anyway to directly rotate a picture box. Do i need to use the image a different way to be able to achieve what I want? Any help is much appreciated.
Make a new class inheriting from picturebox. Use that. You can edit the designer.vb to change the type.
This is pseudocode, untested, so it certainly won't run.
class RotateablePictureBox
inherits picturebox
public property RotationAngle as single
overrides onpaint(e as ...)
e.graphics.rotatetransform(rotationangle)
mybase.onpaint(e)
That's the idea that Hans Passant is talking about (might have to do the DrawImage yourself too and skip the mybase.onpaint - it's done like e.graphics.onpaint(TheImage,dimensions etc...))
This is my first time posting code so let me know how I can improve it for the group. I developed this class using code from http://www.devasp.net/net/articles/display/391.htmlenter code here
I hope this helps. This is the button code
Private Sub btnRotateLeft_Click(sender As Object, e As EventArgs) Handles btnRotateLeft.Click
' IMAGE IS THE NEW OBJECT FROM THE CLASS. PASS THE PICTUREBOX CONTROL(pbItems)
image.RotateLeft(pbItems)
End Sub
This is the class
Imports System.Math
Public Class clsImage
Private wid As Single
Private hgt As Single
Public Function RotateLeft(ByVal picSource As PictureBox) As PictureBox
'ROTATES THE IMAGE LEFT
Dim bm_in = New Bitmap(picSource.Image)
wid = bm_in.Width
hgt = bm_in.Height
Dim corners As Point() = {New Point(0, 0), New Point(wid, 0), New Point(0, hgt), New Point(wid, hgt)}
Dim cx As Single = wid / 2
Dim cy As Single = hgt / 2
Dim i As Long
'ROTATES LEFT
For i = 0 To 3
corners(i).X -= cx
corners(i).Y -= cy
Next i
'THE ROTATION ANGLE IS HARD CODED HERE BUT COULD BE PASS TO THE CLASS
Dim theta As Single = Single.Parse(90) * PI / 180.0
Dim sin_theta As Single = Sin(theta)
Dim cos_theta As Single = Cos(theta)
Dim X As Single
Dim Y As Single
For i = 0 To 3
X = corners(i).X
Y = corners(i).Y
corners(i).X = X * cos_theta + Y * sin_theta
corners(i).Y = -X * sin_theta + Y * cos_theta
Next i
Dim xmin As Single = corners(0).X
Dim ymin As Single = corners(0).Y
For i = 1 To 3
If xmin > corners(i).X Then xmin = corners(i).X
If ymin > corners(i).Y Then ymin = corners(i).Y
Next i
For i = 0 To 3
corners(i).X -= xmin
corners(i).Y -= ymin
Next i
Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * ymin))
Dim gr_out As Graphics = Graphics.FromImage(bm_out)
ReDim Preserve corners(2)
gr_out.DrawImage(bm_in, corners)
picSource.Image = bm_out
Return picSource
End Function
Public Function RotateRight(ByVal picSource As PictureBox) As PictureBox
'ROTATES THE IMAGE RIGHT
Dim bm_in = New Bitmap(picSource.Image)
wid = bm_in.Width
hgt = bm_in.Height
Dim corners As Point() = {New Point(0, 0), New Point(wid, 0), New Point(0, hgt), New Point(wid, hgt)}
Dim cx As Single = wid / 2
Dim cy As Single = hgt / 2
Dim i As Long
'ROTATES RIGHT
For i = 0 To 3
corners(i).X -= cx
corners(i).Y -= cy
Next i
'THE ROTATION ANGLE IS HARD CODED HERE BUT COULD BE PASS TO THE CLASS
Dim theta As Single = Single.Parse(-90) * PI / 180.0
Dim sin_theta As Single = Sin(theta)
Dim cos_theta As Single = Cos(theta)
Dim X As Single
Dim Y As Single
For i = 0 To 3
X = corners(i).X
Y = corners(i).Y
corners(i).X = X * cos_theta + Y * sin_theta
corners(i).Y = -X * sin_theta + Y * cos_theta
Next i
Dim xmin As Single = corners(0).X
Dim ymin As Single = corners(0).Y
For i = 1 To 3
If xmin > corners(i).X Then xmin = corners(i).X
If ymin > corners(i).Y Then ymin = corners(i).Y
Next i
For i = 0 To 3
corners(i).X -= xmin
corners(i).Y -= ymin
Next i
Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * ymin))
Dim gr_out As Graphics = Graphics.FromImage(bm_out)
ReDim Preserve corners(2)
gr_out.DrawImage(bm_in, corners)
picSource.Image = bm_out
Return picSource
End Function
End Class
I am trying to create an animated collapsible panel that consists of three different elements. Each element is created from a panel container that sits on a user control. It is made up of a header panel, a content panel and a footer panel (with the footer panel sitting inside the content panel):
Within each panel I override the draw event and do my own custom drawing. This includes rounding the corners, drawing a border, and filling the background (and drawing text in the cases of the header and footer).
The control also allows users to embed into the content panel at both design time and runtime.
When placed on a form, it looks exactly how I want it to, however, I cannot seem to animate the panel in a seamless 'smooth' transition. It is jerky, jittery and looks horrendous when expanding the panel (even with no content).
The way it should work is that when minimized, the content panel (including the footer panel) shrinks to only be the height of the header panel. The header panel then redraws itself to look different. Then when maximized, the panel basically does everything in reverse.
My animation code looks like such:
Dim m_Height As Integer = Me.Height
Dim m_HeaderHeight As Integer = 40
Dim m_FooterHeight As Integer = 35
Dim ShrinkStepSize As Integer = CInt((m_Height - m_HeaderHeight) / 10)
Dim ExpandStepSize As Integer = CInt((m_Height - m_HeaderHeight) / 4)
Private Sub picMinimize_Click(sender As Object, e As EventArgs) Handles picMinimize.Click
While (Me.Height > m_HeaderHeight)
Me.Height -= Math.Min(Me.Height - m_HeaderHeight, ShrinkStepSize)
Application.DoEvents()
End While
picMaximise.Visible = True
picMinimize.Visible = False
m_Minimized = True
Me.Invalidate(pnlHeader.ClientRectangle, True)
End Sub
Private Sub picMaximise_Click(sender As Object, e As EventArgs) Handles picMaximise.Click
While (Me.Height < m_Height)
Me.Height += Math.Min(m_Height - Me.Height, ExpandStepSize)
Application.DoEvents()
End While
picMaximise.Visible = False
picMinimize.Visible = True
m_Minimized = False
Me.Invalidate(pnlHeader.ClientRectangle, True)
End Sub
And without posting all of my code (unless it's required), here are all my paint events for the header, content and footer panels:
Private Sub pnlHeader_Paint(sender As Object, e As PaintEventArgs) Handles pnlHeader.Paint
Dim rect As Rectangle = pnlHeader.ClientRectangle
rect.X = rect.X + 1
rect.Y = rect.Y + 1
rect.Width -= 2
rect.Height -= 2
'Position the icon elements
picClose.Location = New Point(rect.Width - (picClose.Width + 8), CInt(((rect.Height - picClose.Height) / 2) + 3))
picOptions.Location = New Point(rect.Width - ((picClose.Width + picOptions.Width) + 10), CInt(((rect.Height - picOptions.Height) / 2) + 2))
picMinimize.Location = New Point(rect.Width - ((picMinimize.Width + picOptions.Width + picClose.Width) + 15), CInt(((rect.Height - picMinimize.Height) / 2) + 3))
picMaximise.Location = New Point(rect.Width - ((picMaximise.Width + picOptions.Width + picClose.Width) + 15), CInt(((rect.Height - picMaximise.Height) / 2) + 3))
Dim path As Drawing2D.GraphicsPath = RoundRectangle(rect, CornerRadius, Me.CornerRounding)
If m_Minimized Then
'Draw the background
Using br As Brush = New SolidBrush(Color.White)
e.Graphics.FillPath(br, path)
End Using
'Draw the border
Using br As Brush = New SolidBrush(BorderColour)
e.Graphics.DrawPath(New Pen(br, 1), path)
End Using
End If
'Draw the text
Dim textRect As Rectangle = rect
textRect.X += m_HeaderAdjustment
Using string_format As New StringFormat()
string_format.Alignment = StringAlignment.Near
string_format.LineAlignment = StringAlignment.Center
e.Graphics.DrawString(HeaderText, New Font("Segoe UI", 13, FontStyle.Bold, GraphicsUnit.Pixel), New SolidBrush(Color.FromArgb(157, 159, 162)), textRect, string_format)
End Using
End Sub
Private Sub pnlContent_Paint(sender As Object, e As PaintEventArgs) Handles pnlContent.Paint
Dim rect As Rectangle = pnlContent.ClientRectangle
rect.X = rect.X + 1
rect.Y = rect.Y + 1
rect.Width -= 2
rect.Height -= 2
Dim path As Drawing2D.GraphicsPath = RoundRectangle(rect, CornerRadius, Me.CornerRounding)
'Draw the background
Using br As Brush = New SolidBrush(Color.White)
e.Graphics.FillPath(br, path)
End Using
'Draw the border
Using br As Brush = New SolidBrush(BorderColour)
rect.Inflate(-1, -1)
e.Graphics.DrawPath(New Pen(br, 1), path)
End Using
End Sub
Private Sub pnlFooter_Paint(sender As Object, e As PaintEventArgs) Handles pnlFooter.Paint
Dim rect As Rectangle = pnlFooter.ClientRectangle
rect.X = rect.X + 1
rect.Y = rect.Y + 1
rect.Width -= 2
rect.Height -= 2
Dim rounding As Corners = Corners.BottomLeft Or Corners.BottomRight
Dim path As Drawing2D.GraphicsPath = RoundRectangle(rect, CornerRadius, rounding)
'Draw the background
Using br As Brush = New SolidBrush(FooterBackColour)
e.Graphics.FillPath(br, path)
End Using
'Draw the border
Using br As Brush = New SolidBrush(BorderColour)
e.Graphics.DrawPath(New Pen(br, 1), path)
End Using
'Draw the text
Dim textRect As Rectangle = rect
textRect.X += m_FooterAdjustment
textRect.Y += 1
Using string_format As New StringFormat()
string_format.Alignment = StringAlignment.Near
string_format.LineAlignment = StringAlignment.Center
e.Graphics.DrawString(FooterText, New Font("Segoe UI", 11, FontStyle.Regular, GraphicsUnit.Pixel), New SolidBrush(FooterForeColour), textRect, string_format)
End Using
End Sub
Any help with this would be greatly appreciated.
Thanks heaps.