VB.NET我要用鼠标轨迹画一个矩形框 然后选中控件 。就像星际和魔兽争霸里对部队单位的选中一样~等大神回答这个类继承自Panel , 把它加到你的项目里面,先运行一下 , 然后从工具箱里把它拖到窗体上,然后再向里面添加其它控件就可以了 , 支持Shift加选,Alt减选
Imports System.Linq
Imports System.Collections
Public Class MyPanel
Inherits Panel
' 选择模式,相交还是包含
Enum SelectMode
Intersects
Contains
End Enum
Dim down As New Point(-1, -1)
Dim rect As Rectangle
Dim selected As New List(Of Control)
Dim editting As IEnumerable(Of Control)
Dim mode As SelectMode = SelectMode.Contains
【vb.netunion的简单介绍】Dim shift, alt As Boolean
Public Sub New()
Me.DoubleBuffered = True
End Sub
Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
MyBase.OnMouseDown(e)
down = e.Location
editting = selected.ToArray().ToList()
OnMouseMove(e)
End Sub
Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
MyBase.OnMouseMove(e)
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim loc As New Point(Math.Min(down.X, e.X), Math.Min(down.Y, e.Y))
Dim size As New Size(Math.Abs(down.X - e.X), Math.Abs(down.Y - e.Y))
rect = New Rectangle(loc, size)
Dim cs As New List(Of Control)
For Each c In Controls
cs.Add(c)
Next
Dim a = cs.Where(Function(n As Control) (mode = SelectMode.Contains And rect.Contains(n.Bounds)) Or (mode = SelectMode.Intersects And rect.IntersectsWith(n.Bounds)))
If shift Then editting = a.Union(selected) Else If alt Then editting = selected.Except(a) Else editting = a
Invalidate()
End If
End Sub
Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
MyBase.OnMouseUp(e)
down = New Point(-1, -1)
selected = editting.ToList()
editting = Nothing
Invalidate()
End Sub
Protected Overrides Function ProcessKeyPreview(ByRef m As Message) As Boolean
Dim KeyCode As Keys = CInt(m.WParam) And CInt(Keys.KeyCode)
Dim d As Boolean
If m.Msg = H100 Or m.Msg = H104 Then d = True Else If m.Msg = H101 Or m.Msg = H105 Then d = False Else Return MyBase.ProcessKeyPreview(m)
If KeyCode = Keys.ShiftKey Then
shift = d
ElseIf KeyCode = Keys.Menu Then
alt = d
End If
Return MyBase.ProcessKeyPreview(m)
End Function
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
For Each c As Control In IIf(editting Is Nothing, selected, editting)
e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, c.Left - 1, c.Top - 1, c.Width1, c.Height1)
Next
If (down.X0) Then e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, rect)
End Sub
End Class
如何用vb.net将汉字转换成拼音阿public string hz2py(string hz)//获得汉字的区位码
{
byte[] sarr = System.Text.Encoding.Default.GetBytes(hz);
int len = sarr.Length;
if (len1)
{
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes(hz);
int i1 = (short)(array[0] - '\0');
int i2 = (short)(array[1] - '\0');
//unicode解码方式下的汉字码
//array = System.Text.Encoding.Unicode.GetBytes(hz);
//int i1 = (short)(array[0] - '\0');
//int i2 = (short)(array[1] - '\0');
//int t1 = Convert.ToInt32(i1,16);
//int t2 = Convert.ToInt32(i2,16);
int tmp=i1*256 i2;
string getpychar="*";//找不到拼音码的用*补位
if(tmp=45217tmp=45252){getpychar= "A";}
else if(tmp=45253tmp=45760){getpychar= "B";}
else if(tmp=47761tmp=46317){getpychar= "C";}
else if(tmp=46318tmp=46825){getpychar= "D";}
else if(tmp=46826tmp=47009){getpychar= "E";}
else if(tmp=47010tmp=47296){getpychar= "F";}
else if(tmp=47297tmp=47613){getpychar= "G";}
else if(tmp=47614tmp=48118){getpychar= "H";}
else if(tmp=48119tmp=49061){getpychar= "J";}
else if(tmp=49062tmp=49323){getpychar= "K";}
else if(tmp=49324tmp=49895){getpychar= "L";}
else if(tmp=49896tmp=50370){getpychar= "M";}
else if(tmp=50371tmp=50613){getpychar= "N";}
else if(tmp=50614tmp=50621){getpychar= "O";}
else if(tmp=50622tmp=50905){getpychar= "P";}
else if(tmp=50906tmp=51386){getpychar= "Q";}
else if(tmp=51387tmp=51445){getpychar= "R";}
else if(tmp=51446tmp=52217){getpychar= "S";}
else if(tmp=52218tmp=52697){getpychar= "T";}
else if(tmp=52698tmp=52979){getpychar= "W";}
else if(tmp=52980tmp=53640){getpychar= "X";}
else if(tmp=53689tmp=54480){getpychar= "Y";}
else if(tmp=54481tmp=55289){getpychar= "Z";}
return getpychar;
}
else
{
return hz;
}
}
public string transpy(string strhz)//把汉字字符串转换成拼音码
{
string strtemp="";
int strlen=strhz.Length;
for (int i=0;i=strlen-1;i)
{
strtemp =hz2py(strhz.Substring(i,1));
}
return strtemp;
}
create table tabpy(id int identity,b_begin varbinary(2),b_end varbinary(2),word varchar(2))
insert tabpy select 0xB0A1, 0xB0C4,'A'
union all select 0xB0C5, 0xB2C0,'B'
union all select 0xB2C1, 0xB4ED,'C'
union all select 0xB4EE, 0xB6E9,'D'
union all select 0xB6EA, 0xB7A1,'E'
union all select 0xB7A2, 0xB8C0,'F'
union all select 0xB8C1, 0xB9FD,'G'
union all select 0xB9FE, 0xBBF6,'H'
union all select 0xBBF7, 0xBFA5,'J'
union all select 0xBFA6, 0xC0AB,'K'
union all select 0xC0AC, 0xC2E7,'L'
union all select 0xC2E8, 0xC4C2,'M'
union all select 0xC4C3, 0xC5B5,'N'
union all select 0xC5B6, 0xC5BD,'O'
union all select 0xC5BE, 0xC6D9,'P'
union all select 0xC6DA, 0xC8BA,'Q'
union all select 0xC8BB, 0xC8F5,'R'
union all select 0xC8F6, 0xCBF9,'S'
union all select 0xCBFA, 0xCDD9,'T'
union all select 0xCDDA, 0xCEF3,'W'
union all select 0xCEF4, 0xD1B8,'X'
union all select 0xD1B9, 0xD4D0,'Y'
union all select 0xD4D1, 0xD7F9,'Z'
函数:
create function getfirstpy(@a varchar(200))
returns varchar(100)
as
begin
declare @i int,@j int,@result varchar(100)
set @result=''
set @i=len(@a)
set @j=1
while @j=@i
begin
select @result=@result word from tabpy where cast(substring(@a,@j,1) as varbinary(2)) between b_begin and b_end
set @j=@j 1
end
return @result
end
Vb.net中如何将数组数据显示在dategridview控件中?datagrid不行 , 因为datagrid绑定数据库,因此不能添加一个附加行 。即使在SQL命令中通过union方式进行统计后显示 , 但又会导致datagrid不能新增 。解决办法有2个:1、用MSFlexGrid;2、自己写一个用户控件,大概意思就是里面有2个datagrid,一个大的,专门显示记录,一个小的,不要标题行,专门显示合计数;在里面增加写代码使它们水平同步滚动 。
vb.net问题你是在哪一句出错?
错误“未将对象引用设置到对象的实例 。”一般都是一些Object类型的变量没有初始化(New)导致的
vb.netunion的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、vb.netunion的信息别忘了在本站进行查找喔 。
推荐阅读
- 揭秘空中格斗游戏,揭秘空中格斗游戏视频
- 下载博客,下载博客软件
- java代码解释案例,java典型代码
- linux安驱动的命令 linux驱动视频教程
- oracle补丁查询,oracle打补丁具体步骤
- 小牛助手安卓使用教程,小牛助手破解注册
- 电脑插入u盘怎么自动蓝屏,电脑一插u盘就蓝屏
- 如何搭建go语言 go语言搭建服务器
- ios9.1系统怎么查数据,iphone数据查看