C#中如何制作图片窗体(希望能写出代码)

作者&投稿:常亲 (若有异议请与网页底部的电邮联系)
c# form窗体添加背景图片,代码怎么写?~

有两种方法,方法一:
1、this.BackgroundImage = Image.FromFile(@"图片路径")
2、this.BackgroundImage = this.imageList1.Images[0]
方法二:
imageList设置图片像素只能是在1-256
C# 窗体背景图片怎么跟随窗体变化而变化
背景图单独存放在其它位置后,当窗口的OnResize事件发生时,
对图片缩放后,作为背景。根据此原理,实现如下:
这里借用了一个pictureBox.不改变它的其它属性,如改变Image属性后,编写如下代码
private void Form2_SizeChanged(object sender, System.EventArgs e){loadBackImage();}
private void loadBackImage(){Bitmap bit = new Bitmap(this.Width,this.Height);
Graphics g = Graphics.FromImage(bit);
g.DrawImage(this.pictureBox1.Image,newRectangle(0,0,bit.Width,bit.Height),0,0,this.pictureBox1.Image.Width,this.pictureBox1.Image.Height,GraphicsUnit.Pixel);
this.BackgroundImage = bit;
g.Dispose();}private void Form2_Load(object sender, System.EventArgs e)loadBackImage();}

Access 中的窗体是一种数据库对象,可用于创建数据库应用程序的用户界面。“绑定”窗体直接连接到表或查询之类的数据源,可用于输入、编辑或显示来自该数据源的数据。或者也可以创建“未绑定”窗体。

这是不规则窗体,就是你背景图片是什么样子,你FORM就是什么样子
frmAbout 为一个FROM
aboutwin = new frmAbout();
aboutwin.CreateControlRegionComplete+=new EventHandler(addaboutmenuitem);
aboutwin.InitializeRegion(new Bitmap(Application.StartupPath + "\\about.bmp"));

下面就是处理类
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Threading;
namespace net.emice.Host
{
/// <summary>
///
/// Summary description for BitmapRegion.
/// </summary>
public class BitmapRegionFrom : System.Windows.Forms.Form
{
public EventHandler CreateControlRegionComplete;
private Bitmap mybitmap;
private void CreateControlRegion()
{
// Set our control''s size to be the same as the bitmap
//设置控件大小为位图大小
this.Width = mybitmap.Width;
this.Height = mybitmap.Height;

// No border
//没有边界
this.FormBorderStyle = FormBorderStyle.None;
// Set bitmap as the background image
//将位图设置成窗体背景图片
this.BackgroundImage = mybitmap;
// Calculate the graphics path based on the bitmap supplied
//计算位图中不透明部分的边界
//GraphicsPath graphicsPath = CalculateControlGraphicsPath(bitmap);
//// Apply new region
////应用新的区域
//form.Region = new Region(graphicsPath);
Thread ragiondrawthread = new Thread(new ThreadStart(CalculateControlGraphicsPath));
ragiondrawthread.Start();
}
/// <summary>
/// Calculate the graphics path that representing the figure in the bitmap
/// excluding the transparent color which is the top left pixel.
/// //计算位图中不透明部分的边界
/// </summary>
/// <param name="bitmap">The Bitmap object to calculate our graphics path from</param>
/// <returns>Calculated graphics path</returns>
//private void CalculateControlGraphicsPath( ref System.Windows.Forms.Control control, Bitmap bitmap)
private void CalculateControlGraphicsPath()
{

// Create GraphicsPath for our bitmap calculation
//创建 GraphicsPath
GraphicsPath graphicsPath = new GraphicsPath();
// Use the top left pixel as our transparent color
//使用左上角的一点的颜色作为我们透明色
Color colorTransparent = mybitmap.GetPixel(0, 0);
// This is to store the column value where an opaque pixel is first found.
// This value will determine where we start scanning for trailing opaque pixels.
//第一个找到点的X
int colOpaquePixel = 0;
// Go through all rows (Y axis)
// 偏历所有行(Y方向)
for (int row = 0; row < mybitmap.Height; row++)
{
// Reset value
//重设
colOpaquePixel = 0;
// Go through all columns (X axis)
//偏历所有列(X方向)
for (int col = 0; col < mybitmap.Width; col++)
{
// If this is an opaque pixel, mark it and search for anymore trailing behind
//如果是不需要透明处理的点则标记,然后继续偏历
if (mybitmap.GetPixel(col, row) != colorTransparent)
{
// Opaque pixel found, mark current position
//记录当前
colOpaquePixel = col;
// Create another variable to set the current pixel position
//建立新变量来记录当前点
int colNext = col;
// Starting from current found opaque pixel, search for anymore opaque pixels
// trailing behind, until a transparent pixel is found or minimum width is reached
///从找到的不透明点开始,继续寻找不透明点,一直到找到或则达到图片宽度
for (colNext = colOpaquePixel; colNext < mybitmap.Width; colNext++)
if (mybitmap.GetPixel(colNext, row) == colorTransparent)
break;
// Form a rectangle for line of opaque pixels found and add it to our graphics path
//将不透明点加到graphics path
graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));
// No need to scan the line of opaque pixels just found
col = colNext;
}
}
}
// Return calculated graphics path
this.Region = new Region(graphicsPath);
OnCreateControlRegionComplete();
}
private void OnCreateControlRegionComplete()
{
if (null != CreateControlRegionComplete)
CreateControlRegionComplete(this,new EventArgs());
}
public virtual void InitializeRegion(Bitmap bitmap)
{
mybitmap = bitmap;
CreateControlRegion();
}
}
}

修改窗体的backgroundImage属性啊!


万山特区17735364011: C#中如何制作图片窗体(希望能写出代码) -
焦竖特子: 这是不规则窗体,就是你背景图片是什么样子,你FORM就是什么样子 frmAbout 为一个FROM aboutwin = new frmAbout(); aboutwin.CreateControlRegionComplete+=new EventHandler(addaboutmenuitem); aboutwin.InitializeRegion(new Bitmap...

万山特区17735364011: C#怎么制作图片所示的窗体!(最好一模一样) -
焦竖特子: 新建项目,选择windows窗体应用程序,完成后,解决方案资源管理器中应该有一个winform项目, 右键点击项目,添加,添加新窗体.你这里有两个窗体要创建,所以创建两个新窗体,自己命名 双击你的窗体1:vs会进入设计视图, 找到“工具箱”,拖拽“DataGridView”控件到你的窗体里面,自己拖拽一下位置,拉伸一下大小,即可实现你图示1的样子, 在“属性”面板中,可以自己修改一下这个窗体1的边框颜色.双击你的窗体2:vs会进入设计视图, 找到“工具箱”,拖拽“DataGridView”控件到你的窗体里面,自己拖拽一下位置,拉伸一下大小,同理拖拽两个ComboBox、两个CheckBox至你图示位置.即可实现你图示2的样子,

万山特区17735364011: C#实现窗体绘图 -
焦竖特子: 说下自己的想法: 你可以把图片的地址归到一个集合中,int i=0;设置一个时间值,过了这段时间i++,然后设置显示图片区域的值为 数组名[i]...i如果超过范围了,就归零,这样就能循环了

万山特区17735364011: C# 把一张图片画到窗体上 如何做? -
焦竖特子: C#中有专门的GDI绘图函数,可以从硬盘读取位图,并绘制到目标窗体上,函数名忘了,可以搜

万山特区17735364011: C#创建不规则窗体的几种方式 -
焦竖特子: 现在,C#创建不规则窗体不是一件难事,下面总结一下:一、自定义窗体,一般为规则的图形,如圆、椭圆等.做法:重写Form1_Paint事件(Form1是窗体的名字),最简单的一种情况如下:System.Drawing.Drawing2D.GraphicsPathshape ...

万山特区17735364011: C# 如何在图片框中显示图片 -
焦竖特子: 例如要在pictureBox空间中显示图片一;动态添加pictureBox.Image = Image.FromFile(@"这里填写你的图片的位置"); 二:直接在控件的属性框中点击pictureBox的Image属性,选择本地资...

万山特区17735364011: c#中如何制作自己的窗口
焦竖特子: 这需要用到多态 具体代码如下 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; ...

万山特区17735364011: c# 点击按钮弹出新窗口,在新窗口中插入图片 -
焦竖特子: 在按钮的“button-click”事件中写如下代码:form f2=new form(); f2.show(); 点击按钮弹出新窗口:其中form为窗口的name; 再 在新弹出的窗口的load中:添加一个“picturebox”,把它的image属性弄成图片就可以了

万山特区17735364011: C#提示窗体怎么加图片??/?????/???? -
焦竖特子: 提示窗体?如果你是指MessageBox,它有自带的几种图标,如果想自定义提示窗体那就自己写一个Form做为提示窗体,不使用MessageBox就是了,希望对你有帮助,有疑问请追问或是Hi

万山特区17735364011: 如何在C#(WINDOWS)中实现不规则窗体设计?? -
焦竖特子: 你在的Form1里面重写这个方法,这个例子是把窗体变成椭圆的.具体想变成自己想要的形状的话,建议你研究下C#图像处理的GraphicsPath类 protected override void OnPaint(PaintEventArgs e) { //椭圆 GraphicsPath shape = new GraphicsPath(); shape.AddEllipse(0, 0, this.Width, this.Height); this.Region = new System.Drawing.Region(shape); }

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网