110,533
社区成员
发帖
与我相关
我的任务
分享
//点击checkBox
void ckSel_Click(object sender, EventArgs e)
{
CheckBox ck = (CheckBox)sender;
int tag = (int)ck.Tag;
PictureBox frmPic = (PictureBox)this.Controls[0];
if (ck.Checked)
{
PictureBox viewPic = new PictureBox();
viewPic.Size = new Size(bit[tag].Width, bit[tag].Height);
viewPic.Image = bit[tag];
viewPic.Location = new Point(tag*50,10);
frmPic.Controls.Add(viewPic);
viewPic.BringToFront();
} else{
//按frmPic.Controls内部子控件顺序clear掉
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace tips_mscd
{
public partial class Form1 : Form
{
PrivateFontCollection privateFonts = new PrivateFontCollection(); //字库
Bitmap[] bit = new Bitmap[3]; //定义3个图片
//文字生成图片
private Bitmap DrawBitmapText(string Text, string fontName, int fontSize, Color color, int work_Width, int work_Height, int location_X, int location_Y)
{
privateFonts.AddFontFile(fontName); //自定义字库,*.ttf文件
Bitmap bmp = new Bitmap(work_Width, work_Height);
using (Graphics gr_bmp = Graphics.FromImage(bmp))
{
gr_bmp.DrawImage(bmp, new Rectangle(0, 0, work_Width, work_Height), new Rectangle(0, 0, work_Width, work_Height), GraphicsUnit.Pixel);
}
Graphics g = Graphics.FromImage(bmp);
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
Font the_font = new Font(privateFonts.Families[0], fontSize, FontStyle.Regular);
SolidBrush brush = new SolidBrush(color);
g.DrawString(Text, the_font, brush, location_X, location_Y);
return bmp;
}
//读取图片
private Bitmap ReadBitmapImage(string fileName)
{
Bitmap bmp = new Bitmap(fileName);
return bmp;
}
public Form1()
{
InitializeComponent();
bit[0] = DrawBitmapText("春有百花秋有月\n\r夏有凉风冬雨雪", "fz.ttf", 18, Color.Red, 200, 50, 0, 0); //生成文字图片
bit[1] = ReadBitmapImage(@"m1.png"); //读取本地图片
bit[2] = ReadBitmapImage(@"m2.png"); //读取本地图片
PictureBox pB = new PictureBox();
pB.BackColor = Color.Transparent;
pB.Size = new Size(500, 500);
pB.Location = new Point(10, 50);
this.Controls.Add(pB);
}
//生成checkBox
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 3; i++)
{
CheckBox ckSel = new CheckBox();
ckSel.Text = "第" + i;
ckSel.Tag = i;
ckSel.Location = new Point(10+i*70, 10);
ckSel.Width = 50;
ckSel.Click += new EventHandler(ckSel_Click);
this.Controls.Add(ckSel);
}
}
//点击checkBox
void ckSel_Click(object sender, EventArgs e)
{
for (int i=0;i<3;i++)
{
CheckBox dsel = (CheckBox)this.Controls[i+1];
dsel.Checked = false;
}
CheckBox ck = (CheckBox)sender;
ck.Checked = !ck.Checked;
int tag = (int)ck.Tag;
if (ck.Checked)
{
PictureBox view = (PictureBox)this.Controls[0];
view.Image = bit[tag];
}
}
}
}
private void Form1_Load(object sender, EventArgs e) {
imageLayerPanel1.CreateCanvas(new Size(200, 200));
imageLayerPanel1.BeginUpdate();
m_il = new ImageLayer();
m_il.Image = this.GetDesktopImage(Point.Empty, new Size(150, 150));
m_il.Rectangle = new Rectangle(30, 30, 150, 150);
ImageLayer il = new ImageLayer();
il.Image = this.GetDesktopImage(Point.Empty, new Size(100, 100));
il.Rectangle = new Rectangle(-10, 0, 100, 20);
il.Visable = true;
imageLayerPanel1.Layers.Add(il);
il = new ImageLayer();
il.Image = this.GetDesktopImage(Point.Empty, new Size(100, 100));
il.Rectangle = new Rectangle(10, 0, 100, 50);
il.Visable = true;
imageLayerPanel1.Layers.Add(il);
imageLayerPanel1.Layers.Add(m_il);
imageLayerPanel1.EndUpdate();
}
private void button1_Click(object sender, EventArgs e) {
m_il.Visable = !m_il.Visable;
}
private ImageLayerCollection _Layers;
public ImageLayerCollection Layers {
get {
if (_Layers == null) _Layers = new ImageLayerCollection(this);
return _Layers;
}
}
public virtual void ReDraw() {
if (m_imgCanvas != null) m_imgCanvas.Dispose();
m_imgCanvas = new Bitmap(m_szCanvas.Width, m_szCanvas.Height);
using (Graphics g = Graphics.FromImage(m_imgCanvas)) {
foreach (ImageLayer il in this.Layers) {
if (!il.Visable) continue;
g.DrawImage(il.Image, il.Rectangle);
}
}
this.Invalidate();
}