如何为visual basic制作保存图片框按钮? [英] How to make a save picturebox button for visual basic?

查看:86
本文介绍了如何为visual basic制作保存图片框按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我目前正在制作草图板程序,我想为它添加更多功能。我想补充两件事。 1)保存按钮,2)撤销按钮。

I'm currently working on a sketch pad program and I am wanting to add more features to it. I would like to add two things. 1) a save button, 2) an undo button.

这是现在的当前代码: 

This is the current code now: 

Public Class frmSketch

    Dim GraphDemo As Graphics
    Dim LinePreview As Graphics
    Dim GraphPen As New Pen(Color.Black, 1)
    Dim X, Y As Integer
    Dim R As Integer = 0
    Dim G As Integer = 0
    Dim B As Integer = 0
    Dim W As Integer = 1
    Dim Start As Boolean = False


    Private Sub frmSketch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GraphDemo = picDisplay.CreateGraphics
        LinePreview = PicLinePreview.CreateGraphics
        GraphPen.Width = W
        GraphPen.Color = Color.FromArgb(R, G, B)
        GraphPen.StartCap = Drawing2D.LineCap.Round
        GraphPen.EndCap = Drawing2D.LineCap.Round
    End Sub

    Private Sub picDisplay_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picDisplay.MouseDown
        Start = True
        If e.Button = Windows.Forms.MouseButtons.Left Then
            GraphPen.Color = Color.FromArgb(R, G, B)
        End If
        If e.Button = Windows.Forms.MouseButtons.Right Then
            GraphPen.Color = picDisplay.BackColor
        End If
        X = e.X
        Y = e.Y
    End Sub

    Private Sub picDisplay_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picDisplay.MouseMove
        If Start = True Then
            GraphDemo.DrawLine(GraphPen, X, Y, e.X, e.Y)
            X = e.X
            Y = e.Y
        End If
    End Sub

    Private Sub picDisplay_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picDisplay.MouseUp
        Start = False
    End Sub

    Private Sub hsbRed_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbRed.Scroll
        R = hsbRed.Value

        PicColPreview.BackColor = Color.FromArgb(R, G, B)
    End Sub

    Private Sub hsbWidth_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbWidth.Scroll
        W = hsbWidth.Value

        GraphPen.Width = W
        LinePreview.Clear(Color.White)
        LinePreview.DrawLine(GraphPen, 10, 20, 30, 20)
    End Sub

    Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
        End
    End Sub

    Private Sub hsbBlue_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbBlue.Scroll
        B = hsbBlue.Value

        PicColPreview.BackColor = Color.FromArgb(R, G, B)
    End Sub

    Private Sub hsbGreen_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbGreen.Scroll
        G = hsbGreen.Value
        PicColPreview.BackColor = Color.FromArgb(R, G, B)
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        picDisplay.Image = Nothing

    End Sub

End Class


感谢您的帮助

Thank you for the help

推荐答案


我正在研究草图板程序,我想为它添加更多功能。我想补充两件事。 1)保存按钮,2)撤销按钮。

I'm currently working on a sketch pad program and I am wanting to add more features to it. I would like to add two things. 1) a save button, 2) an undo button.

您尚未说明问题所在。 可以将"保存"按钮添加到"设计器"中的表单中。   您需要添加代码才能进行实际保存。 那需要文件路径和文件名吗? 这是你遇到问题的原因吗?b
https://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog(v = vs.110)的.aspx

You haven't indicated what the problem is.  The save button can be added to your form in Designer.    You would need to add code to do the actual saving.  That requires a file path and a file name?  Is that where you are running into a problem?
https://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog(v=vs.110).aspx

要保存的图像可能是图片框图像。

https://msdn.microsoft.com/en-us/library/9t4syfhh(v = vs.110).aspx

The image to be saved is presumably the picturebox image.
https://msdn.microsoft.com/en-us/library/9t4syfhh(v=vs.110).aspx

对于撤消,您将无法使用当前架构实现该功能。  您需要更改绘图过程,以便鼠标按下和鼠标移动事件将绘图信息添加到集合中。 这应该是一个
的自定义对象集合,其中包括笔详细信息和绘图位置信息,例如标记一行的两个点。  每次收集更改时,您都会通过迭代绘制
指令的集合来重绘图像。  您可以通过从集合末尾删除操作并重新绘制来撤消操作。  "清除"按钮初始化集合并重新绘制图像。

https://vbdotnetblog.wordpress。 com / graphics / graphics-methodology /

For the undo, you won't be able to implement that with your current architecture.   You need to change the drawing process so that the mouse down and mouse move events add the drawing information to a collection.  That should probably be a collection of custom objects that include the pen details and the drawing location information, such as two points marking the ends of a line.   Each time that collection changes you redraw the image by iterating over the collection of drawing instructions.   You 'undo' an action by removing it from the end of the collection, and redrawing.  The Clear button initializes the collection and redraws the image.
https://vbdotnetblog.wordpress.com/graphics/graphics-methodology/


这篇关于如何为visual basic制作保存图片框按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆