1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
| Public Class Form1
Dim X As Single
Dim Y As Single
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
' Dim MyDialog As New ColorDialog()
If (FontDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
Label1.Font = FontDialog1.Font
End If
'[
If (ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
Label1.ForeColor = ColorDialog1.Color
' Dim br As Brush = New SolidBrush(ColorDialog1.Color)
br = New SolidBrush(ColorDialog1.Color)
End If
Dim drawBrush As New System.Drawing.SolidBrush(ColorDialog1.Color)
']
Label1.BackColor = Color.Transparent
Label1.Text = TextBox1.Text
Label1.Show()
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "Впишите сюда ваш текст."
Label1.Hide()
Timer1.Start()
Timer1.Interval = 1
Label1.Parent = PictureBox1
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
'=====
Private isMouseDown As Boolean = False 'признак удерживания кнопки мыши
Private StartPoint As Point 'начальная позиция элемента управления
Private Sub Label1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then 'если нажата левая кнопка мыши
isMouseDown = True
StartPoint = e.Location 'запоминаем текущую позицию элемента управления
Label1.Cursor = Cursors.SizeAll 'меняем вид указателя мыши над элементом управления
End If
End Sub
Private Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
isMouseDown = False
Label1.Cursor = Cursors.Default 'восстанавливаем вид курсора
End Sub
Private Sub Label1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
If isMouseDown Then 'если кнопка мыши удерживается
'вычисляем новые координаты элемента управления
Label1.Left += (e.X - StartPoint.X)
Label1.Top += (e.Y - StartPoint.Y)
End If
End Sub
Private Sub Label1_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.LocationChanged
'если большая часть элемента управления выходит за границу формы, возвращаем его в центр
Dim w2 As Integer = Convert.ToInt32(Label1.Width / 2)
Dim h2 As Integer = Convert.ToInt32(Label1.Height / 2)
If Label1.Top < -h2 Or Label1.Left < -w2 Or Label1.Top > Me.ClientSize.Height - h2 Or Label1.Left > Me.ClientSize.Width - w2 Then
Label1.Location = New Point(Convert.ToInt32(Me.ClientSize.Width / 2) - w2, Convert.ToInt32(Me.ClientSize.Height / 2) - h2)
isMouseDown = False
Label1.Cursor = Cursors.Default
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.FilterIndex = 2
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
PictureBox1.Image = Image.FromFile(openFileDialog1.FileName)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Catch ex As Exception
End Try
End If
End Sub
Dim br As Brush
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
SaveFileDialog1.Filter = "Png|*.Png|GIF|*.gif"
'Dim BM As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim BM As New Bitmap(PictureBox1.Image)
Dim G As Graphics = Graphics.FromImage(BM)
G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
' G.DrawString(TextBox1.Text, New Font("Consolas", 15), Brushes.Blue, 10, 10
G.DrawString(TextBox1.Text, New Font(FontDialog1.Font.Name, FontDialog1.Font.Size), br, Label1.Left, Label1.Top)
PictureBox1.Image = BM
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
' PictureBox1.Image.Save(SaveFileDialog1.FileName)
BM.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png)
Process.Start(SaveFileDialog1.FileName)
End If
End Sub
End Class |