【问题标题】:How to design my program properly? [closed]如何正确设计我的程序? [关闭]
【发布时间】:2014-02-16 09:21:13
【问题描述】:

我在许多示例中看​​到,程序员只使用一张薄而窄的图片或一些小图片来设计他们的程序并扩展这些图片,或者有时他们将许多图标放在一张图片中,然后再使用它们。

我想知道他们是如何做到的,例如如何使用小图片作为我的表单背景。

顺便说一句,对不起我的英语不好。

【问题讨论】:

  • 哪种技术? Winforms 还是 WPF?请添加适当的标签。你的问题是关于UI设计的,请去掉设计标签。
  • 您的意思是“如何在我的表单背景上平铺一张较小的图片”?
  • 是的,我就是这个意思

标签: vb.net winforms


【解决方案1】:

许多开发人员将多个图像放在一个图像中。您可以使用graphics 对象对图像进行draw a portion

假设一张图片包含 10 张大小为 16x16 (px) 的图片。

Dim image As New Bitmap((10 * 16), 16)

现在,如果要将第三张图像绘制为背景图像,您可以这样做:

Public Class MyForm
    Inherits Form

    Public Sub New()
        MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.AllPaintingInWmPaint, True)
    End Sub

    Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)

        'The source image.
        Dim image As Bitmap = My.Resources.myimage

        'The number of the image to be drawn. (1 - 10)
        Dim nr As Integer = 3

        'The x axis of the image portion.
        Dim x As Integer = (16 * (nr - 1))

        'Destination rectangle. (MyForm)
        Dim destinationRect As New Rectangle(0, 0, Me.Width, Me.Height)

        'Source rectangle. The portion of the image to be drawn.
        Dim imagePortionRect As New Rectangle(x, 0, 16, 16)

        'Draw image.
        e.Graphics.DrawImage(image, destinationRect, imagePortionRect, GraphicsUnit.Pixel)

        MyBase.OnPaint(e)

    End Sub

End Class

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 2010-11-04
    • 2021-05-17
    • 1970-01-01
    • 2015-04-12
    • 2011-03-13
    相关资源
    最近更新 更多