⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 PDA上的透明解决方法,找了很久才找到的,WINDOW MOIBLE 5.0以上才支持
💻 CS
字号:
using System;
using System.ComponentModel; 
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Forms;


namespace AlphaBlendTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
        }

        void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            this.DrawLabelOnPictureBox(this.label1, this.pictureBox1, e.Graphics);
            //throw new NotImplementedException();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
            SelectPictureDialog SPD = new SelectPictureDialog();
            
            if (DialogResult.OK == SPD.ShowDialog())
            {
                Bitmap bmp = new Bitmap(SPD.FileName);
                this.pictureBox1.Image = Image.FromHbitmap(bmp.GetHbitmap());
                this.label1.Text = SPD.FileName.Substring(SPD.FileName.LastIndexOf('\\')+1);
            }

        }

        private void DrawLabelOnPictureBox(Label label, PictureBox targetPB, Graphics grx)
        {
            Point targetOffset = targetPB.Location;

            Rectangle drawBounds = label.Bounds;

            drawBounds.X -= targetPB.Location.X;

            drawBounds.Y -= targetPB.Location.Y;

            if (label.TextAlign == ContentAlignment.TopLeft)
            {
                grx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), drawBounds);
            }

            else if (label.TextAlign == ContentAlignment.TopCenter)
            {

                SizeF size = grx.MeasureString(label.Text, label.Font);

                int left = drawBounds.X + label.Width / 2 - (int)size.Width / 2;

                Rectangle rect = new Rectangle(left, drawBounds.Top, (int)size.Width, (int)size.Height);

                grx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), rect);

            }

            else if (label.TextAlign == ContentAlignment.TopRight)
            {

                SizeF size = grx.MeasureString(label.Text, label.Font);

                int left = drawBounds.Right - (int)size.Width;

                Rectangle rect = new Rectangle(left, drawBounds.Top, (int)size.Width, (int)size.Height);

                grx.DrawString(label.Text, label.Font, new SolidBrush(label.ForeColor), rect);

            }

        }

        private void label1_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox1.Invalidate();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            label1.Text += "+1"; 
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -