Advertisement
netrosly

Note - GDI

Feb 1st, 2015
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.32 KB | None | 0 0
  1. 'Random Controls: Note
  2. 'By Nettro ;P
  3. Imports System.Drawing.Drawing2D
  4.  
  5. Public Class Note
  6.     Inherits Panel
  7.     Sub New()
  8.         Me.DoubleBuffered = True
  9.     End Sub
  10. #Region "Functions"
  11. #Region "Modules & Functions"
  12.     Public Sub DrawRoundRect(g As Graphics, p As Pen, x As Single, y As Single, width As Single, height As Single, _
  13.      radius As Single)
  14.         Dim gp As New GraphicsPath()
  15.  
  16.         gp.AddLine(x + radius, y, x + width - (radius * 2), y)
  17.         ' Line
  18.         gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90)
  19.         ' Corner
  20.         gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2))
  21.         ' Line
  22.         gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90)
  23.         ' Corner
  24.         gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height)
  25.         ' Line
  26.         gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90)
  27.         ' Corner
  28.         gp.AddLine(x, y + height - (radius * 2), x, y + radius)
  29.         ' Line
  30.         gp.AddArc(x, y, radius * 2, radius * 2, 180, 90)
  31.         ' Corner
  32.         gp.CloseFigure()
  33.  
  34.         g.DrawPath(p, gp)
  35.         gp.Dispose()
  36.     End Sub
  37.     Public Sub FillRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  38.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  39.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed
  40.         g.FillPie(b, r.X, r.Y, d, d, 180, 90)
  41.         g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90)
  42.         g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  43.         g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  44.         g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  45.         g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  46.         g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  47.         g.SmoothingMode = mode
  48.     End Sub
  49.     Public Sub FillNotTopRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  50.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  51.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
  52.         g.FillPie(b, r.X, r.Y, 1, 1, 180, 90)
  53.         g.FillPie(b, r.X + r.Width - d, r.Y, 1, 1, 270, 90)
  54.         g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  55.         g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  56.         ' g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  57.         g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  58.         g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  59.         g.SmoothingMode = mode
  60.     End Sub
  61.     Public Sub FillNotBottomRoundedRectangle(ByVal g As Drawing.Graphics, ByVal r As Rectangle, ByVal d As Integer, ByVal b As Brush)
  62.         Dim mode As Drawing2D.SmoothingMode = g.SmoothingMode
  63.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
  64.         g.FillPie(b, r.X, r.Y, d, d, 180, 90)
  65.         g.FillPie(b, r.X + r.Width - d, r.Y, d, d, 270, 90)
  66.         'g.FillPie(b, r.X, r.Y + r.Height - d, d, d, 90, 90)
  67.         '  g.FillPie(b, r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90)
  68.         g.FillRectangle(b, CInt(r.X + d / 2), r.Y, r.Width - d, CInt(d / 2))
  69.         ' g.FillRectangle(b, r.X, CInt(r.Y + d / 2), r.Width, CInt(r.Height - d))
  70.         '   g.FillRectangle(b, CInt(r.X + d / 2), CInt(r.Y + r.Height - d / 2), CInt(r.Width - d), CInt(d / 2))
  71.         g.SmoothingMode = mode
  72.     End Sub
  73. #End Region
  74. #End Region
  75.     Property Back_color As Color = Color.White
  76.     Property Border_color As Color = Color.FromArgb(124, 186, 75)
  77.     Property IcoSize As Size = New Size(54, 54)
  78.     Property IcoLocation As Point = New Point(12, 8)
  79.     Property Fill_color As Color = Color.FromArgb(138, 193, 92)
  80.     Property Border_color2 As Color = Color.FromArgb(199, 254, 161)
  81.     Property Text_color As Color = Color.FromArgb(233, 233, 233)
  82.     Property Link_color As Color = Color.FromArgb(104, 154, 57)
  83.     Dim Link_hover As Boolean = False
  84.     Dim Link2_hover As Boolean = False
  85.     Event Link1_Clicked()
  86.     Event Link2_Clicked()
  87.     Event Closed_Clicked()
  88.     Property IconType As IcoType = IcoType.Text
  89.     Property Image As Image
  90.     Enum IcoType
  91.         Image
  92.         Text
  93.     End Enum
  94.     Property Link_text As String = "Link to facebook."
  95.     Property Link2_text As String = "Sign out or Login in."
  96.     Property header_text As String = "25:00x"
  97.     Property para_text As String = "This is a note and you are looking at it right now because you like it."
  98.     Property In_Circle_Text As String = "None"
  99.  
  100.     Private Sub Note_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
  101.         If e.Button = Windows.Forms.MouseButtons.Left Then
  102.             If New Rectangle(Me.Width - 28, 20, 20, 20).Contains(e.X, e.Y) Then
  103.                 RaiseEvent Closed_Clicked()
  104.             End If
  105.             If New Rectangle(28, Me.Height - 25, 80, 12).Contains(e.X, e.Y) Then
  106.                 RaiseEvent Link1_Clicked()
  107.             End If
  108.             If New Rectangle(Me.Width - 105, Me.Height - 25, 90, 12).Contains(e.X, e.Y) Then
  109.                 RaiseEvent Link2_Clicked()
  110.             End If
  111.         End If
  112.     End Sub
  113.  
  114.     Private Sub Note_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
  115.         If New Rectangle(Me.Width - 105, Me.Height - 25, 90, 12).Contains(e.X, e.Y) Then
  116.             Link2_hover = True
  117.             Me.Refresh()
  118.         Else
  119.             Link2_hover = False
  120.         End If
  121.         If New Rectangle(28, Me.Height - 25, 80, 12).Contains(e.X, e.Y) Then
  122.             Link_hover = True
  123.             Me.Refresh()
  124.         Else
  125.             Link_hover = False
  126.         End If
  127.         If New Rectangle(Me.Width - 28, 20, 20, 20).Contains(e.X, e.Y) Or New Rectangle(Me.Width - 105, Me.Height - 25, 90, 12).Contains(e.X, e.Y) Or New Rectangle(28, Me.Height - 25, 80, 12).Contains(e.X, e.Y) Then
  128.             Cursor = Cursors.Hand
  129.         Else
  130.             Cursor = Cursors.Arrow
  131.         End If
  132.     End Sub
  133.     Private Sub Note_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  134.         e.Graphics.Clear(Back_color)
  135.         e.Graphics.SmoothingMode = SmoothingMode.HighQuality
  136.         FillRoundedRectangle(e.Graphics, New Rectangle(18, 18, Me.Width - 26, Me.Height - 26), 8, New SolidBrush(Border_color))
  137.         FillRoundedRectangle(e.Graphics, New Rectangle(20, 20, Me.Width - 30, Me.Height - 30), 8, New SolidBrush(Fill_color))
  138.         '   DrawRoundRect(e.Graphics, New Pen(Border_color), 20, 20, Me.Width - 30, Me.Height - 30, 6)
  139.         Dim rect = New Rectangle(5, 5, 65, 65)
  140.         Dim brushs = New LinearGradientBrush(rect, Border_color, Border_color2, 90.0!)
  141.         e.Graphics.FillEllipse(brushs, rect)
  142.         e.Graphics.FillEllipse(New SolidBrush(Fill_color), New Rectangle(8, 8, 60, 60))
  143.         If IconType = IcoType.Text Then
  144.             e.Graphics.DrawString(In_Circle_Text, New Font("Arial", 10.5, FontStyle.Regular), New SolidBrush(Text_color), New Rectangle(8, 16, 58, 40), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  145.         Else
  146.             e.Graphics.DrawImage(Image, New Rectangle(IcoLocation, IcoSize))
  147.         End If
  148.         e.Graphics.DrawString("x", New Font("Arial", 10.5, FontStyle.Regular), New SolidBrush(Text_color), New Rectangle(Me.Width - 28, 20, 20, 20), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  149.         e.Graphics.DrawString(header_text, New Font("Arial", 16.5, FontStyle.Regular), New SolidBrush(Text_color), New Rectangle(75, 32, 80, 35), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  150.         e.Graphics.DrawString(para_text, New Font("Arial", 8.5, FontStyle.Regular), New SolidBrush(Text_color), New Rectangle(75, 60, Me.Width - 86, Me.Height - 84), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  151.         If Link_hover = False Then
  152.             e.Graphics.DrawString(Link_text, New Font("Arial", 7.5, FontStyle.Regular), New SolidBrush(Link_color), New Rectangle(28, Me.Height - 25, 80, 12), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  153.         Else
  154.             e.Graphics.DrawString(Link_text, New Font("Arial", 7.5, FontStyle.Underline), New SolidBrush(Link_color), New Rectangle(28, Me.Height - 25, 80, 12), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  155.         End If
  156.         If Link2_hover = False Then
  157.             e.Graphics.DrawString(Link2_text, New Font("Arial", 7.5, FontStyle.Regular), New SolidBrush(Link_color), New Rectangle(Me.Width - 105, Me.Height - 25, 90, 12), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  158.         Else
  159.             e.Graphics.DrawString(Link2_text, New Font("Arial", 7.5, FontStyle.Underline), New SolidBrush(Link_color), New Rectangle(Me.Width - 105, Me.Height - 25, 90, 12), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  160.         End If
  161.     End Sub
  162.  
  163. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement