高手请进===》制作不规则形状控件的问题??

LoveEgg 2005-05-08 10:32:04
在我的自定义控件上,我用GDI+绘制了一些图像,此时怎样将我没有绘制的地方从控件区域中删除,即使控件成为不规则的形状(只保留我绘制的部分)??
...全文
351 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
LoveEgg 2005-05-13
  • 打赏
  • 举报
回复
cqhxd() 的办法可以,多谢。
苹果软件 2005-05-13
  • 打赏
  • 举报
回复
wuyazhe(我的宝贝叫阿刺)
很棒,你的代码完全可以,我试过了,而且做了一个
兔子-顾问 2005-05-12
  • 打赏
  • 举报
回复
那个代码默认1秒刷新一次,你10毫秒刷新看还慢不慢。
骑车的娃儿 2005-05-12
  • 打赏
  • 举报
回复
如果仅仅是做线条控件没必要取每一个点,那样速度当然慢了
提供一个思路
1:Line控件中提供DrawLine函数,参数为它的起始点和结束点
2:根据那2个点设置控件Left,top,Width,Height,需要注意全局坐标和内部坐标的转换问题。
3: 没必要在控件中用.NET的DrawLine画线在剪切,而是传入组成这条直线的点数组,这样就根本上解决了你那个需要提取Graphics的Path的问题,这样一条直线4个点,如果有箭头也就7个点,很容易得到
dim FramePoints As Point()
.....
.....
GraphicsPath.AddPolygon(FramePoints) 'FramePoints是按顺序排列的点数组
Me.Region = New Region(GraphicsPath)
LoveEgg 2005-05-12
  • 打赏
  • 举报
回复
首先感谢各位的提点。!

我和 cqhxd() 兄的情况相似。我也是画流程图,要让线条自动跟框图移动。

wuyazhe(我的宝贝叫阿刺) 兄的办法可以实现,但我觉得效率好像差了点,当我拖动一个框图时可能会有多根线条跟着移动,这时都需要重设Region,感觉速度就不行了。

不知用API来取色会不会快些。

骑车的娃儿 2005-05-11
  • 打赏
  • 举报
回复
晕,老兄到底有没有看清楚我说什么
苹果软件 2005-05-11
  • 打赏
  • 举报
回复
你写一个类对象来控制呀,类里面写你的具体怎么drawline的喽
兔子-顾问 2005-05-11
  • 打赏
  • 举报
回复
上面的例子,在执行文件目录需要找一个scocca.gif图片。你随便着个gif,改名叫这个就可以看效果
兔子-顾问 2005-05-11
  • 打赏
  • 举报
回复
Imports System.Drawing.Drawing2D
Public Class Form2
Inherits System.Windows.Forms.Form
Private IsDraging As Boolean = False 'Varible for draging from
Private lCurX, lCurY As Long 'needed for current x, y values
Private WithEvents tTimer As Timer = New Timer() 'setup timer (no need for a formcontrol)
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'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) Then
components.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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
Me.ClientSize = New System.Drawing.Size(272, 150)
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "Form2"
Me.Text = "Form2"

End Sub

#End Region

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'avvio in un altro thread la costruzione della grafica
'Dim t2 As System.Threading.Thread = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf drawScocca))
't2.Start()
drawScocca()
End Sub

Private Sub drawScocca()
Dim Path As New GraphicsPath()

Dim g As Graphics = Me.CreateGraphics
Dim b As New Bitmap("scocca.gif")

Dim x, y, i As Long
Dim rect As Rectangle

Dim colorFirst As Color = b.GetPixel(1, 1)
For x = 0 To b.Width - 1
For y = 0 To b.Height - 1
If b.GetPixel(x, y).Equals(colorFirst) Then
'non lo disegno perch?devo fare la trasparenza
Else
rect = New Rectangle(x, y, 1, 1)
Path.AddRectangle(rect)
End If
Next y
Next x

Me.Region = New Region(Path)
End Sub


Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim g As Graphics = Me.CreateGraphics
Dim b As New Bitmap("scocca.gif")

g.DrawImage(b, 0, 0, b.Width, b.Height)
g.Dispose()
End Sub

Private Sub Form2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
lCurX = e.X : lCurY = e.Y 'Set the Current x and y values
IsDraging = True 'Begin Draging Form
tTimer.Enabled = True 'Enable Drag Timer
End Sub

Private Sub tTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tTimer.Tick
'Checks the state of the mouseevent and moves form Accordingly
If IsDraging = True Then
'Move the form accordingly to cursor x, y positions (minus) the current form x, y positions
Dim curxx As Integer = Cursor.Position.X
Dim curyy As Integer = Cursor.Position.Y
Me.SetDesktopLocation(curxx - lCurX, curyy - lCurY)
End If
'tTimer.Enabled = False 'Cancel timer, no longer needed
End Sub

Private Sub Form2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
IsDraging = False 'No Longer Moving Form
tTimer.Enabled = False 'Cancel Timer
End Sub
End Class


以上是个例子,用图片作为背景的异形窗体。控件参考着来?
aSalt 2005-05-11
  • 打赏
  • 举报
回复
up
骑车的娃儿 2005-05-11
  • 打赏
  • 举报
回复
这个控件我以前做流程图的时候就做好了,但是我不明白你只用Drawline画线能做出来?你怎么编辑你用drawline画的那些线?比如我现在拖动一个Node,这个时候关联到这个NOde上的线需要跟着变化,或者我需要拖动或者删除一根线,你只用Drawline能做到?就算你能做到,也没有做成控件这么方便吧
苹果软件 2005-05-11
  • 打赏
  • 举报
回复
哈哈,你是做流程图的呀,那就用drawline喽,我就是用哪做的char控件呀
骑车的娃儿 2005-05-11
  • 打赏
  • 举报
回复
再说了,你说调整控件的z顺序,2个直线控件相交你考虑过没?3个呢?4个呢?这个不是调整z顺序能够做到的
骑车的娃儿 2005-05-11
  • 打赏
  • 举报
回复
用drawline当然简单了,不过他达不到要求呀,比如做一个流程图控件,里面的直线需要随时可以编辑的,甚至拖拉定位,用Drawline不太适合,更何况这个直线控件(并不是说是个水平或者垂直的线,而是一个可以任意方向的直线)前面还有个箭头。你去看看其他有关流程图的软件就明白了
苹果软件 2005-05-11
  • 打赏
  • 举报
回复
你说说你的具体用法,我看能不能帮你
苹果软件 2005-05-11
  • 打赏
  • 举报
回复
用drawline画一条斜线就可以了,干吗非要透明呢?你可以调整控件的z顺序呀,不用透明就可以实现的。
骑车的娃儿 2005-05-11
  • 打赏
  • 举报
回复
to psongchao(林达电子):
做直线控件不用不规则控件行吗?你想想一根斜线的时候会是什么样子?,如果你的控件是个矩形,你想想你这个斜着的直线能达到要求?
苹果软件 2005-05-10
  • 打赏
  • 举报
回复
郁闷,怀疑,想不明白,你们是拿vb.net做什么用的
苹果软件 2005-05-10
  • 打赏
  • 举报
回复
做直线控件也用不上不规则的呀,让控件的高设成1个像素不就可以吗?我做了以整套的xp控件库,20多个控件,也没有遇到过不规则控件呀
骑车的娃儿 2005-05-10
  • 打赏
  • 举报
回复
楼上的,不规则控件很多情况下都要用到,比如做一个直线控件
加载更多回复(3)

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧