| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 533 人关注过本帖
标题:[求助]将vb.net代码转换成C#
只看楼主 加入收藏
tanghuawei
Rank: 4
来 自:美丽的湖南
等 级:业余侠客
威 望:3
帖 子:531
专家分:220
注 册:2006-3-16
结帖率:100%
收藏
 问题点数:0 回复次数:0 
[求助]将vb.net代码转换成C#

加入一个CommonDialog控件,一个TextBox控件,一个PictureBox控件,两个CommandButton控件。
代码如下:
'声明API函数BitBlt
Private Declare Function BitBlt Lib "gdi32" ()

(ByValhDestDC As Long,ByValx As Long,ByValy As Long,ByValnWidth As Long,ByVal nHeight As Long,ByVal hSrcDC As Long,ByVal xSrc As Long,ByValySrc As Long,ByValdwRop As Long)'As Long

'初始化

Private Sub Form_Load()

TextBox1.Top = 0 : TextBox1.Left = 0

TextBox1.MaxLength = 2 : TextBox1.BorderStyle = 0

End Sub

'修改字体

Private Sub Command1_Click()

'设置“取消”为True
CommonDialog1.CancelError = True

On Error GoTo ErrHandler

'设置Flags属性
CommonDialog1.Flags = cdlCFEffects Or cdlCFBoth

'显示“字体”对话框  

CommonDialog1.ShowFont()

TextBox1.Font.Name = CommonDialog1.FontName

TextBox1.Font.Size = CommonDialog1.FontSize

TextBox1.Font.Bold = CommonDialog1.FontBold

TextBox1.Font.Italic = CommonDialog1.FontItalic

PictureBox1.Font.Size = CommonDialog1.FontSize
TextBox1.Width=2*PictureBox1.TextWidth(TextBox1.Text)TextBox1.Height=PictureBox1.TextHeight(TextBox1.Text)

Exit Sub
ErrHandler:
'用户按了“取消”按钮

Exit SubEnd Sub
'生成字模
Private Sub Command2_Click()

Dim Wp() As Byte
ReDim Wp(PictureBox1.TextWidth(TextBox1.Text)*

PictureBox1.TextWidth(TextBox1.Text))As Byte

Dim Nbyte, Q(7) As Integer

Dim Cy, Cx As Integer

Dim Dot As Integer

Dim Z As Long
Dot = 0 : Nbyte = 0

BrightV = 16000000
Z=BitBlt(PictureBox1.hDC,0,0,300,300,Form1.hDC,1,1,&HCC0020)PictureBox1.Refresh
For Cy=PictureBox1.TextHeight(TextBox1.Text)To 0 Step-1For Cx=PictureBox1.TextWidth(TextBox1.Text)To 0 Step-1

Z = PictureBox1.Point(Cx, Cy)

'得到该点的颜色信息

If Z < BrightV Then
Q(Dot) = 1 '该点为黑

Else

Q(Dot) = 0 '该点为白 
End If
If Dot = 7 Then

'将8个点的信息存入一个字节中 
Wp(Nbyte) = Q(7) * 128 + Q(6) * 64 + Q(5) * 32 + Q(4) * 16 + Q(3) * 8 + Q(2) * 4 + Q(1) * 2 + Q(0) * 1

Nbyte = Nbyte + 1

End If

Dot = Dot + 1

If Dot = 8 Then Dot = 0
Next Cx
Next CyEnd Sub
麻烦各位兄弟,我不太会VB.NET,帮我转换一下,谢谢!

[此贴子已经被作者于2006-9-1 9:18:34编辑过]

搜索更多相关主题的帖子: 代码 
2006-09-01 09:16
快速回复:[求助]将vb.net代码转换成C#
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029814 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved