首页 新闻 会员 周边 捐助

C#picturebox如何做透明,不覆盖下一层的GDI画的图

0
悬赏园豆:20 [已关闭问题] 关闭于 2018-10-29 15:58

如何使得picturebox2不覆盖红色画出来的线?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox2.Parent = pictureBox1;
}

    private Point _pictureBoxBigXY_L;   //存放[波形放大方框]的起点坐标

    private Point _pictureBoxBigXY_R;   //存放鼠标移动时的坐标

    private Point _pictureBoxBigXY_M;   //存放最后调整后[波形放大框]的位置坐标

    private Color BigXYBackColor = Color.FromArgb(255, 255, 255);
    private Color BigXYButtonBackColor = Color.FromArgb(200, 255, 255, 255);
    private Color BigXYButtonForeColor = Color.FromArgb(0, 0, 0);

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        Graphics ag = this.pictureBox1.CreateGraphics();
        
        ag.DrawLine(new Pen(Color.Red, 2), 10, 10, 500, 500);

        if (e.Button == MouseButtons.Left)
        {
            _pictureBoxBigXY_L.X = e.X;
            _pictureBoxBigXY_L.Y = e.Y;

            pictureBox2.Location = _pictureBoxBigXY_L;  //更新[波形放大框]位置坐标
            pictureBox2.Width = 200;
            pictureBox2.Height = 200;
            return;
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    }

    private void pictureBox2_Paint(object sender, PaintEventArgs e)
    {
        this.pictureBox2.BackColor = Color.FromArgb(50, Color.Transparent);
    }
}

}

不如吃茶去的主页 不如吃茶去 | 初学一级 | 园豆:200
提问于:2018-10-26 15:16
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册