cs_bernardo67
Messages postés
41
Date d'inscription
dimanche 28 mai 2006
Statut
Membre
Dernière intervention
20 janvier 2009
29 déc. 2008 à 13:23
Voilà un bout de code que j'avais trouvé pour les boutons, peut-etre que ça pourra t'aider.
Bon courage
Bernardo.
Imports
System.Drawing
Imports
System.Drawing.Drawing2D
Imports
System.Drawing.Graphics
Public
Class Form1
Inherits System.Windows.Forms.Form
#
Region
" Windows Form Designer generated code "
'<System.STAThread()> Public Shared Sub Main()
' Application.EnableVisualStyles()
' Application.DoEvents()
' Application.Run(New Form1) 'remplacez frmApp par le nom de votre form.
'End Sub
Public
Sub
New()
MyBase.New()
'This call is required by the Windows Form Designer.InitializeComponent()
Application.EnableVisualStyles()
'Add any initialization after the InitializeComponent() call
End
Sub
'Form overrides dispose to clean up the component list.
Protected
Overloads
Overrides
Sub Dispose(
ByVal disposing
As
Boolean)
If disposing
Then
If
Not (components
Is
Nothing)
Thencomponents.Dispose()
End
If
End
If
MyBase.Dispose(disposing)
End
Sub
'Required by the Windows Form Designer
Private components
As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend
WithEvents Button3
As System.Windows.Forms.Button
Friend
WithEvents Button1
As System.Windows.Forms.Button
Friend
WithEvents Button2
As System.Windows.Forms.Button
Friend
WithEvents Button4
As System.Windows.Forms.Button
Friend
WithEvents Button5
As System.Windows.Forms.Button
Friend
WithEvents Button6
As System.Windows.Forms.Button
Friend
WithEvents Button7
As System.Windows.Forms.Button
Friend
WithEvents Button8
As System.Windows.Forms.Button
Friend
WithEvents Button9
As System.Windows.Forms.Button<System.Diagnostics.DebuggerStepThrough()>
Private
Sub InitializeComponent()
Dim resources
As System.Resources.ResourceManager =
New System.Resources.ResourceManager(
GetType(Form1))
Me.Button3 =
New System.Windows.Forms.Button
Me.Button1 =
New System.Windows.Forms.Button
Me.Button2 =
New System.Windows.Forms.Button
Me.Button4 =
New System.Windows.Forms.Button
Me.Button5 =
New System.Windows.Forms.Button
Me.Button6 =
New System.Windows.Forms.Button
Me.Button7 =
New System.Windows.Forms.Button
Me.Button8 =
New System.Windows.Forms.Button
Me.Button9 =
New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button3
'
Me.Button3.BackColor = System.Drawing.SystemColors.ActiveCaption
Me.Button3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
Me.Button3.Location =
New System.Drawing.Point(416, 96)
Me.Button3.Name =
"Button3"
Me.Button3.Size =
New System.Drawing.Size(104, 56)
Me.Button3.TabIndex = 1
Me.Button3.Text =
"Etoile"
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.Blue
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button1.Font =
New System.Drawing.Font(
"Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
CType(0,
Byte))
Me.Button1.ForeColor = System.Drawing.Color.White
Me.Button1.Location =
New System.Drawing.Point(240, 72)
Me.Button1.Name =
"Button1"
Me.Button1.Size =
New System.Drawing.Size(106, 48)
Me.Button1.TabIndex = 0
Me.Button1.Text =
"Next"
'
'Button2
'
Me.Button2.BackColor = System.Drawing.Color.FromArgb(
CType(192,
Byte),
CType(64,
Byte),
CType(0,
Byte))
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button2.Font =
New System.Drawing.Font(
"Microsoft Sans Serif", 7.8!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
CType(0,
Byte))
Me.Button2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
Me.Button2.Location =
New System.Drawing.Point(240, 8)
Me.Button2.Name =
"Button2"
Me.Button2.Size =
New System.Drawing.Size(104, 48)
Me.Button2.TabIndex = 2
Me.Button2.Text =
"Back"
'
'Button4
'
Me.Button4.BackColor = System.Drawing.Color.Green
Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button4.Location =
New System.Drawing.Point(32, 136)
Me.Button4.Name =
"Button4"
Me.Button4.Size =
New System.Drawing.Size(112, 56)
Me.Button4.TabIndex = 3
Me.Button4.Text =
"Losange"
'
'Button5
'
Me.Button5.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button5.Image =
CType(resources.GetObject(
"Button5.Image"), System.Drawing.Image)
Me.Button5.Location =
New System.Drawing.Point(264, 264)
Me.Button5.Name =
"Button5"
Me.Button5.Size =
New System.Drawing.Size(88, 40)
Me.Button5.TabIndex = 4
Me.Button5.Text =
"Dessin"
'
'Button6
'
Me.Button6.BackColor = System.Drawing.Color.Purple
Me.Button6.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
Me.Button6.Location =
New System.Drawing.Point(240, 128)
Me.Button6.Name =
"Button6"
Me.Button6.Size =
New System.Drawing.Size(88, 48)
Me.Button6.TabIndex = 5
Me.Button6.Text =
"Triangle"
'
'Button7
'
Me.Button7.BackColor = System.Drawing.Color.FromArgb(
CType(192,
Byte),
CType(192,
Byte),
CType(255,
Byte))
Me.Button7.Location =
New System.Drawing.Point(440, 8)
Me.Button7.Name =
"Button7"
Me.Button7.Size =
New System.Drawing.Size(120, 64)
Me.Button7.TabIndex = 6
Me.Button7.Text =
"Rectangle arrondis"
'
'Button8
'
Me.Button8.Location =
New System.Drawing.Point(272, 338)
Me.Button8.Name =
"Button8"
Me.Button8.TabIndex = 7
Me.Button8.Text =
"Fermer"
'
'Button9
'
Me.Button9.Location =
New System.Drawing.Point(272, 216)
Me.Button9.Name =
"Button9"
Me.Button9.Size =
New System.Drawing.Size(80, 24)
Me.Button9.TabIndex = 8
Me.Button9.Text =
"Modif Form"
'
'Form1
'
Me.AutoScaleBaseSize =
New System.Drawing.Size(6, 15)
Me.ClientSize =
New System.Drawing.Size(608, 344)
Me.Controls.Add(
Me.Button9)
Me.Controls.Add(
Me.Button8)
Me.Controls.Add(
Me.Button7)
Me.Controls.Add(
Me.Button6)
Me.Controls.Add(
Me.Button5)
Me.Controls.Add(
Me.Button4)
Me.Controls.Add(
Me.Button2)
Me.Controls.Add(
Me.Button3)
Me.Controls.Add(
Me.Button1)
Me.Name =
"Form1"
Me.Text =
"Modification de la forme des boutons au run time"
Me.ResumeLayout(
False)
End
Sub#
End
Region
Private
Sub Form1_Load(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles
MyBase.Load
' Defition des points du polygone
' modification de l'aspect de la form
Dim pts()
As Point = { _
New Point(15, 15), _
New Point(45, 15), _
New Point(45, 5), _
New Point(75, 25), _
New Point(45, 45), _
New Point(45, 35), _
New Point(15, 35)}
' Création du GraphicsPath.
Dim polygon_path
As
New GraphicsPath(FillMode.Alternate)polygon_path.AddPolygon(pts)
' Converti le GraphicsPath en une Region.
Dim polygon_region =
New Region(polygon_path)
' Limite le bouton à la région.Button1.Region = polygon_region
' Fait que le bouton remplit la région.Button1.SetBounds(Button1.Location.X, Button1.Location.Y, pts(3).X + 5, pts(4).Y + 5)
'*****************
Dim pts2()
As Point = { _
New Point(75, 15), _
New Point(45, 15), _
New Point(45, 5), _
New Point(15, 25), _
New Point(45, 45), _
New Point(45, 35), _
New Point(75, 35)}
' Création du GraphicsPath.
Dim polygon_path2
As
New GraphicsPath(FillMode.Winding)polygon_path2.AddPolygon(pts2)
' Converti le GraphicsPath en une Region.
Dim polygon_region2 =
New Region(polygon_path2)
' Limite le bouton à la région..Button2.Region = polygon_region2
' Fait que le bouton remplit la région.Button2.SetBounds(Button2.Location.X, Button2.Location.Y, pts2(0).X + 15, pts2(5).Y + 15)
Dim pts1
As Point() = { _
New Point(75, 5), _
New Point(100, 50), _
New Point(150, 50), _
New Point(112, 75), _
New Point(150, 150), _
New Point(75, 100), _
New Point(0, 150), _
New Point(37, 75), _
New Point(0, 50), _
New Point(50, 50)}
Dim polygon_path1
As
New GraphicsPath(FillMode.Winding)polygon_path1.AddPolygon(pts1)
Dim polygon_region1 New Region(polygon_path1)Button3.Region polygon_region1
Button3.SetBounds(Button3.Location.X, Button3.Location.Y, 150, 150)
Button3.BackColor = Color.BlueViolet
Dim pts4
As Point() = { _
New Point(30, 50), _
New Point(90, 10), _
New Point(150, 50), _
New Point(90, 90)}
Dim polygon_path4
As
New GraphicsPath(FillMode.Winding)polygon_path4.AddPolygon(pts4)
Dim polygon_region4 New Region(polygon_path4)Button4.Region polygon_region4
Button4.SetBounds(Button4.Location.X, Button4.Location.Y, 180, 100)
Dim pts6
As Point() = { _
New Point(30, 70), _
New Point(90, 10), _
New Point(150, 70)}
Dim polygon_path6
As
New GraphicsPath(FillMode.Winding)polygon_path6.AddPolygon(pts6)
Dim polygon_region6 New Region(polygon_path6)Button6.Region polygon_region6
Button6.SetBounds(Button6.Location.X, Button6.Location.Y, 180, 100)
End
Sub
' Dessine des lignes à l'écran
Private
Sub Form1_Paint(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.PaintEventArgs)
Handles
MyBase.Paint
Dim white_pen
As
New Pen(Color.White)
Dim y
As
Long
Dim wid
As
Long =
Me.ClientSize.Width
For y = 5
To
Me.ClientSize.Height
Step 10e.Graphics.DrawLine(white_pen, 0, y, wid, y)
Next y
End
Sub
Private
Sub Button1_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button1.Click
Dim grfx
As Graphics = CreateGraphics()
Dim path
As
New GraphicsPathpath.AddEllipse(40, 40, 140, 70)
' Utilise lee path pour construire un Path
Dim pthGrBrush
As
New PathGradientBrush(path)
' Peint le path en bleupthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255)
Dim colors As Color() {Color.FromArgb(255, 0, 255, 255)}pthGrBrush.SurroundColors colors
grfx.FillEllipse(pthGrBrush, 0, 0, 240, 120)
MsgBox(
"Click sur Next Dessine ellipse")
End
Sub
Private
Sub Button3_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button3.Click
Dim grfx
As Graphics = CreateGraphics()
Dim path
As
New GraphicsPath
Dim points
As Point() = { _
New Point(75, 0), _
New Point(100, 50), _
New Point(150, 50), _
New Point(112, 75), _
New Point(150, 150), _
New Point(75, 100), _
New Point(0, 150), _
New Point(37, 75), _
New Point(0, 50), _
New Point(50, 50)}
' Utilise le tableau de points pour construire le Pathpath.AddLines(points)
' Utilise le path pour construire une path gradient
Dim pthGrBrush
As
New PathGradientBrush(path)
' met la couleur rouge au centrepthGrBrush.CenterColor = Color.FromArgb(255, 255, 0, 0)
' définit la couleur des points
Dim colors
As Color() = { _Color.FromArgb(255, 0, 0, 0), _
Color.FromArgb(255, 0, 255, 0), _
Color.FromArgb(255, 0, 0, 255), _
Color.FromArgb(255, 255, 255, 255), _
Color.FromArgb(255, 0, 0, 0), _
Color.FromArgb(255, 0, 255, 0), _
Color.FromArgb(255, 0, 0, 255), _
Color.FromArgb(255, 255, 255, 255), _
Color.FromArgb(255, 0, 0, 0), _
Color.FromArgb(255, 0, 255, 0)}
pthGrBrush.SurroundColors = colors
' remplit le path avec les couleurs gradientgrfx.FillPath(pthGrBrush, path)
MsgBox(
"Vous avez cliqué sur Etoile, dessine une étoile")
End
Sub
Private
Sub Button4_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button4.ClickMsgBox(
"Vous avez cliqué sur losange")
End
Sub
Private
Sub Button5_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button5.Click
' Crée un path et dessine une ellipse.
Dim mybrush
As Brushes
Dim drawBrush
As
New SolidBrush(Color.PaleGreen)
Dim grfx
As Graphics = CreateGraphics()
Dim myEllipse
As
New RectangleF(20, 20, 150, 100)
Dim myPath
As
New GraphicsPathgrfx.FillRectangle(drawBrush, myEllipse)
myPath.AddEllipse(myEllipse)
myPath.AddRectangle(Rectangle.Round(myEllipse))
myPath.FillMode = FillMode.Alternate
' Dessine le path a l'écran.
Dim myPen
As
New Pen(Color.Yellow, 16)
Dim myPen1
As
New Pen(Color.Green, 10)grfx.DrawPath(myPen, myPath)
grfx.DrawPath(myPen1, myPath)
Dim myPen2
As
New Pen(Color.Blue, 6)grfx.DrawPath(myPen2, myPath)
Dim myPen3
As
New Pen(Color.Red, 2)
Dim stringText
As
String =
"Exemple"
Dim family
As
New FontFamily(
"Arial")
Dim myfontStyle
As
Integer =
CInt(FontStyle.Italic)
Dim emSize
As
Integer = 32
Dim origin
As
New Point(24, 50)
Dim format
As StringFormat = StringFormat.GenericDefault
' Ajoute le texte au nPathmyPath.AddString(stringText, family, myfontStyle, emSize, origin, format)
grfx.DrawPath(myPen3, myPath)
End
Sub
Private
Sub Button2_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button2.ClickMsgBox(
"Click sur Back")
End
Sub
Private
Sub Button7_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button7.Click
Dim x
As
Integer = Button7.Size.Height
Dim y
As
Integer = Button7.Size.Width
' pseudo coins arrondis
Dim pts()
As Point = { _
New Point(y, x - 5), _
New Point(y - 5, x), _
New Point(5, x), _
New Point(0, x - 5), _
New Point(0, 5), _
New Point(5, 0), _
New Point(y - 5, 0), _
New Point(y, 5)}
' Création GraphicsPath.
Dim polygon_path
As
New GraphicsPath(FillMode.Alternate)polygon_path.AddPolygon(pts)
' Convertit le Path en région
Dim polygon_region =
New Region(polygon_path)
'Limite le path à la régionButton7.Region = polygon_region
' Le bouton remplit la régionButton7.SetBounds(Button7.Location.X, Button7.Location.Y, y, x)
MsgBox(
"Vous avez arrondi les angles du bouton. La taille du bouton reste inchangée")
End
Sub
Private
Sub Button6_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button6.ClickMsgBox(
"Vous avez cliqué sur triangle")
End
Sub
Private
Sub Button8_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button8.Click
Me.Close()
End
Sub
Private
Sub Button9_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button9.Click
Dim ptsF
As Point() = { _
New Point(0, 0), _
New Point(640, 0), _
New Point(640, 240), _
New Point(320, 480), _
New Point(0, 240) _}
Dim polygon_pathF
As
New GraphicsPath(FillMode.Winding)polygon_pathF.AddPolygon(ptsF)
Dim polygon_regionf =
New Region(polygon_pathF)
Me.Region = polygon_regionfSetBounds(
Me.Location.X,
Me.Location.Y, 640, 480)
End
SubEnd
Class