我的目标是更改背景图像并将其SizeMode设置为Stretch.到目前为止尝试过很多想法?
编辑:我在C#表单应用程序中工作.尝试简单设置bg图片的大小模式:
picturebox1.BackgroundImage = Properties.Resources.Image;
picturebox1.SizeMode = PictureBoxSizeMode.StretchImage;
Run Code Online (Sandbox Code Playgroud)
试图四处走动......没有成功......
这就是我在我的文件上创建和编写的内容:
Create_Directory = @"" + path;
Create_Name = file_name;
private void Create_File(string Create_Directory, string Create_Name )
{
string pathString = Create_Directory;
if (!System.IO.Directory.Exists(pathString)) { System.IO.Directory.CreateDirectory(pathString); }
string fileName = Create_Name + ".txt";
pathString = System.IO.Path.Combine(pathString, fileName);
if (!System.IO.File.Exists(pathString)) { System.IO.File.Create(pathString); }
///ERROR BE HERE:
System.IO.StreamWriter file = new System.IO.StreamWriter(pathString);
file.WriteLine(Some_Method(MP.Mwidth, MP.Mheight, MP.Mtype, "" ));
file.Close();
}
Run Code Online (Sandbox Code Playgroud)
这里的问题,我整天都在争吵,就是在我创建文件后编写文件.所以,我的程序创建一个文件就好了,然后在写之前发出错误:
"mscorlib.dll中发生了'System.IO.IOException'类型的未处理异常"
"附加信息:该进程无法访问文件'D:\ Projects\Project 15\Project 15\world\world maps\A.txt',因为它正由另一个进程使用."
有趣的是,当我再次运行程序并尝试创建一个已经存在的文件时,正如您所看到的,它会跳过文件创建,转到编写并且工作正常,我真的希望我的程序创建文件并在没有文件的情况下编写不得不重新运行...我在这里看不到什么?:S
我试图在我的图片框上写一些文字,所以我认为最简单和最好的事情是在它上面绘制标签.这就是我做的:
PB = new PictureBox();
PB.Image = Properties.Resources.Image;
PB.BackColor = Color.Transparent;
PB.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
PB.Size = new System.Drawing.Size(120, 30);
PB.Location = new System.Drawing.Point(100, 100);
lblPB.Parent = PB;
lblPB.BackColor = Color.Transparent;
lblPB.Text = "Text";
Controls.AddRange(new System.Windows.Forms.Control[] { this.PB });
Run Code Online (Sandbox Code Playgroud)
我得到没有PictureBoxes的空白页面.我究竟做错了什么?
我不确定是否可以将图像的一部分插入到图片框中,但是我想创建一个500*500像素的图像,然后通过设置它来将它的部分用作可连接的50*50个小块.图片框内的图像位置......
通过使用图形可以做出类似的事吗?我对它不太熟悉......(我说的是C#表单应用程序......)
在c#表单中,我创建了一个新的绘制方法:
private void thisPolygon(PaintEventArgs e)
{
Pen clrBlue = new Pen(Color.Blue, 3);
Point[] Wst = new Point[5];
Wst[0] = new Point(20, 350);
Wst[1] = new Point(110, 200);
Wst[2] = new Point(200, 190);
Wst[3] = new Point(210, 275);
Wst[4] = new Point(190, 400);
Wst[5] = new Point(50, 390);
e.Graphics.DrawPolygon(clrBlue, Wst);
}
Run Code Online (Sandbox Code Playgroud)
现在,我该怎么称呼它?我不能让它工作,这不起作用:
private void Form1_Load(object sender, EventArgs e)
{
thisPolygon(); ///I've tried adding some stuff in brackets area, failed.
}
Run Code Online (Sandbox Code Playgroud)