没有合适的资源?快使用搜索试试~ 我知道了~
VB2010 知识宝库
5星 · 超过95%的资源 需积分: 9 30 下载量 116 浏览量
2015-05-24
08:31:18
上传
评论
收藏 393KB DOC 举报
温馨提示
试读
36页
VB2010 知识宝库 一.窗体事件 1.打印文字。 方法一:在窗体上打印文字 Dim g As Graphics = Me.CreateGraphics Dim mBrush As New SolidBrush(Color.Red) Dim mFont As New Font("宋体", 18) g.DrawString("测试", mFont, mBrush, 0, 10) (0 为横坐标,10 为纵坐标) 方法二:在窗体上画文字 Dim m As Graphics ················
资源推荐
资源详情
资源评论
VB2010 知识宝库
一.窗体事件
1.打印文字。
方法一:在窗体上打印文字
Dim g As Graphics = Me.CreateGraphics
Dim mBrush As New SolidBrush(Color.Red)
Dim mFont As New Font("宋体", 18)
g.DrawString("测试", mFont, mBrush, 0, 10)
(0 为横坐标,10 为纵坐标)
方法二:在窗体上画文字
Dim m As Graphics
m = Me.CreateGraphics
m.DrawString("This is a diagonal line drawn on the control", _
New Font("Arial", 10), Brushes.Gold, New PointF(300.0F, 444.0F))
m.Dispose()
方法三:在图片框上打印文字
Public Class Form2
' This example creates a PictureBox control on the form and draws to it.
' This example assumes that the Form_Load event handler method is connected
' to the Load eventof the form.
Private pictureBox1 As New PictureBox()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
' Dock the PictureBox to the form andset its background to white.
pictureBox1.Dock = DockStyle.Fill
pictureBox1.BackColor = Color.White
' Connect the Paint eventof the PictureBox to the event handler method.
AddHandler pictureBox1.Paint, AddressOf Me.pictureBox1_Paint
' Add the PictureBox control to the Form.
Me.Controls.Add(pictureBox1)
End Sub 'Form1_Load
Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs)
' Create a local version of the graphics objectfor the PictureBox.
Dim g As Graphics = e.Graphics
' Draw a stringon the PictureBox.
g.DrawString("This is a diagonal line drawn on the control", _
New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F))
' Draw a line in the PictureBox.
g.DrawLine(System.Drawing.Pens.Red, PictureBox1.Left, _
PictureBox1.Top, PictureBox1.Right, PictureBox1.Bottom)
End Sub 'pictureBox1_Paint
End Class
2.关闭窗体
窗体.Dispose
3. 创建一个透明度为 75%的窗体
Private Sub CreateMyOpaqueForm()
' Create a new form.
Dim form2 As New Form()
' Set the text displayed in the caption.
form2.Text = "My Form"
' Set the opacity to 75%.
form2.Opacity = 0.75
' Size the form to be 300 pixels in height and width.
form2.Size = New Size(300, 300)
' Display the form in the center of the screen.
form2.StartPosition = FormStartPosition.CenterScreen
' Display the form as a modal dialog box.
form2.ShowDialog()
4.用代码在窗体添加一个按钮.
Dim button1 As New Button()
' Set the button to return a value of OK when clicked.
button1.DialogResult = DialogResult.OK
' Add the button to the form.
Controls.Add(button1)
button1.Text = 123
5.自动生成一个窗体并创建两个按钮
(点击Cancle窗体自动关闭,如果他失去焦点,他不仅会响还会晃)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
' Create a new instance of the form.
Dim form1 As New Form()
' Create two buttons to use as the accept and cancel buttons.
Dim button1 As New Button()
Dim button2 As New Button()
' Set the text of button1 to "OK".
button1.Text = "OK"
' Set the position of the button on the form.
button1.Location = New Point(10, 10)
' Set the text of button2 to "Cancel".
button2.Text = "Cancel"
' Set the position of the button based on the location of button1.
button2.Location = _
New Point(button1.Left, button1.Height + button1.Top + 10)
' Set the caption bar text of the form.
form1.Text = "My Dialog Box"
' Display a help button on the form.
form1.HelpButton = True
' Define the border style of the form to a dialog box.
form1.FormBorderStyle = FormBorderStyle.FixedDialog
' Set the MaximizeBox to false to remove the maximize box.
form1.MaximizeBox = False
' Set the MinimizeBox to false to remove the minimize box.
form1.MinimizeBox = False
' Set the accept button of the form to button1.
form1.AcceptButton = button1
' Set the cancel button of the form to button2.
form1.CancelButton = button2
' Set the start position of the form to the center of the screen.
form1.StartPosition = FormStartPosition.CenterScreen
' Add button1 to the form.
form1.Controls.Add(button1)
' Add button2 to the form.
form1.Controls.Add(button2)
' Display the form as a modal dialog box.
form1.ShowDialog()
End Sub
演练:使用 WPF 设计器生成视频浏览器
6.产生此效果
Public Class Form1
' Create a new form.
Dim mdiChildForm As New Form
Dim mdiChildForm1 As New Form
Dim mdiChildForm2 As New Form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Set the IsMdiContainer property to true.
IsMdiContainer = True
' Set the child form's MdiParent property to
' the current form.
mdiChildForm.MdiParent = Me
mdiChildForm1.MdiParent = Me
mdiChildForm2.MdiParent = Me
mdiChildForm.Show()
mdiChildForm1.Show()
mdiChildForm2.Show()
mdiChildForm.Text = 1
mdiChildForm1.Text = 2
mdiChildForm2.Text = 3
End Sub
End Class
7. 改变窗体的背景颜色
Dim ctl As Control
IsMdiContainer = True
' Loop through controls,
' looking for controls of MdiClient type.
For Each ctl In Me.Controls
剩余35页未读,继续阅读
资源评论
- xiaoxiaojiangxue2015-06-22感觉还不错,初学者
- sinat_214964092015-05-28对于初学vb的是个不错的资料,都是用例子说明每个内容,简单易懂
燊炽sc
- 粉丝: 22
- 资源: 115
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功