【发布时间】:2023-03-18 02:00:01
【问题描述】:
我正在从左侧开始在面板中绘制矩形。
当我到达面板的右侧时,我想将之前绘制的矩形向左移动,以便有空间绘制另一个矩形,依此类推。
哪种方法最简单?
我正在使用 System.Drawings.Graphics 绘图。
我正在使用 Winforms。代码是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FFViewer
{
public partial class Form1 : Form
{
[DllImport("shlwapi.dll")]
public static extern int ColorHLSToRGB(int H, int L, int S);
int x=0;
int y=300;
int h = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
panel_Paint();
x = x + 40;
h = h + 40;
if (h >= 240)
h = 0;
}
private void panel_Paint()
{
int val;
Color color;
val = ColorHLSToRGB(h, 128, 240);
Graphics g = panel1.CreateGraphics();
color = ColorTranslator.FromWin32(val);
SolidBrush sb = new SolidBrush( color );
g.FillRectangle(sb, x, y, 40, 100);
}
}
}
所以,当我在右侧绘制最新的矩形时,我想将所有矩形向左移动以留出空间在右侧绘制另一个。
附:我没有足够的声誉来发布图片:(
【问题讨论】:
-
你有没有尝试过?
-
向我们展示您已经做过的事情,发布之前和之后的图片,指定正在使用的技术(例如:Winforms 或 WPF)...
-
要么将它们绘制在不同的位置,要么绘制到位图中并移动位图