none
不规则窗体或(控件),求教各位,谢谢!!! RRS feed

  • 问题

  • 我在窗体上画了一个矩形,并在两头各画了一个扇形:,我想把窗体或控件只显示出所画的样子,求教方法,谢谢!!!

    我在网上找到圆型,扇形等不规则的方法,但没找到复合型的,谢谢!!!

     e.Graphics.DrawArc(mpen, New Rectangle(New Point(Me.Width * 0.05, Me.Height * 0.012), New Size(Me.Width * 0.9, Me.Height * 0.08)), 0, -180)
     e.Graphics.DrawRectangle(mpen, New Rectangle(New Point(Me.Width * 0.05, Me.Height * 0.05), New Size(Me.Width * 0.9, Me.Height * 0.89)))
     e.Graphics.DrawArc(mpen, New Rectangle(New Point(Me.Width * 0.05, Me.Height * 0.9), New Size(Me.Width * 0.9, Me.Height * 0.08))

    2012年5月23日 4:43

答案

  • 你好,

    我觉得你的问题应该分成两个部分1。如何创建自定义控件和自定义窗体。2。如何创建不规则图形的窗体。

    我假设你的第一问题已经是没有问题了(这是先诀条件), 复合型的图形取决于你的数学功底,用分段函数来勾出图形的特征,这里不再赘述。下面是一个例子(注释的地方是画圆形的),你可以好好参考一下。

    Public Class Form1
        Private mouseX, mouseY As Integer
        Private myMouseDown As Boolean
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Dim g As New System.Drawing.Drawing2D.GraphicsPath
            g.AddString("YQY" & vbCrLf & "888", _
            System.Drawing.FontFamily.GenericSansSerif, _
            System.Drawing.FontStyle.Bold, 200, _
            New Point(0, 0), _
            System.Drawing.StringFormat.GenericDefault)
            'g = New System.Drawing.Drawing2D.GraphicsPath()
            'g.AddEllipse(50, 50, 200, 200)
            Me.BackColor = Color.Red
            Me.Region = New System.Drawing.Region(g)
            g.Dispose()
            Me.AutoScaleBaseSize = New System.Drawing.Size(0, 0)
            Me.ClientSize = New System.Drawing.Size(500, 450)
            button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
            button1.ForeColor = System.Drawing.Color.Black
            button1.Location = New System.Drawing.Point(425, 18)
            button1.Size = New System.Drawing.Size(20, 20)
            Me.Controls.Add(button1)
            button1.Text = "X"
            Me.Location = New System.Drawing.Point(50, 50)
    
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Me.Close()
        End Sub
        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal _
         e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
            myMouseDown = True
            mouseX = Cursor.Position.X - Me.Location.X
            mouseY = Cursor.Position.Y - Me.Location.Y
        End Sub
        Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e _
            As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
            Static LastCursor As Point
            Dim NowCursor As Point = New Point(Cursor.Position.X, Cursor.Position.Y)
            If Point.op_Inequality(NowCursor, LastCursor) Then
                If myMouseDown Then
                    Me.Location = New System.Drawing.Point(Cursor.Position.X _
                    - mouseX, Cursor.Position.Y - mouseY)
                End If
                LastCursor = Cursor.Position
            End If
        End Sub
        Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As  _
            System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
            myMouseDown = False
        End Sub
    
    End Class


    No code, No fact.

    2012年5月24日 7:14

全部回复

  • 你好,

    我觉得你的问题应该分成两个部分1。如何创建自定义控件和自定义窗体。2。如何创建不规则图形的窗体。

    我假设你的第一问题已经是没有问题了(这是先诀条件), 复合型的图形取决于你的数学功底,用分段函数来勾出图形的特征,这里不再赘述。下面是一个例子(注释的地方是画圆形的),你可以好好参考一下。

    Public Class Form1
        Private mouseX, mouseY As Integer
        Private myMouseDown As Boolean
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Dim g As New System.Drawing.Drawing2D.GraphicsPath
            g.AddString("YQY" & vbCrLf & "888", _
            System.Drawing.FontFamily.GenericSansSerif, _
            System.Drawing.FontStyle.Bold, 200, _
            New Point(0, 0), _
            System.Drawing.StringFormat.GenericDefault)
            'g = New System.Drawing.Drawing2D.GraphicsPath()
            'g.AddEllipse(50, 50, 200, 200)
            Me.BackColor = Color.Red
            Me.Region = New System.Drawing.Region(g)
            g.Dispose()
            Me.AutoScaleBaseSize = New System.Drawing.Size(0, 0)
            Me.ClientSize = New System.Drawing.Size(500, 450)
            button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
            button1.ForeColor = System.Drawing.Color.Black
            button1.Location = New System.Drawing.Point(425, 18)
            button1.Size = New System.Drawing.Size(20, 20)
            Me.Controls.Add(button1)
            button1.Text = "X"
            Me.Location = New System.Drawing.Point(50, 50)
    
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Me.Close()
        End Sub
        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal _
         e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
            myMouseDown = True
            mouseX = Cursor.Position.X - Me.Location.X
            mouseY = Cursor.Position.Y - Me.Location.Y
        End Sub
        Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e _
            As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
            Static LastCursor As Point
            Dim NowCursor As Point = New Point(Cursor.Position.X, Cursor.Position.Y)
            If Point.op_Inequality(NowCursor, LastCursor) Then
                If myMouseDown Then
                    Me.Location = New System.Drawing.Point(Cursor.Position.X _
                    - mouseX, Cursor.Position.Y - mouseY)
                End If
                LastCursor = Cursor.Position
            End If
        End Sub
        Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As  _
            System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
            myMouseDown = False
        End Sub
    
    End Class


    No code, No fact.

    2012年5月24日 7:14
  • 谢谢!!!,参考了你的例子,解决了我的问题,谢谢!!!
    2012年5月24日 14:01