解决  PictureBox福彩12选5走势图被清除

tim8w

知名会员
已加入
2020年9月8日
留言内容
61
编程经验
10+
我有一个PictureBox,可以将其拖放到另一个PictureBox上。如果按TAB键,则放置在PictureBox中的福彩12选5走势图会消失。知道要阻止此事件发生的事件吗?下图显示了放下"Greater Than"图片到SteelBlue PictureBox上,然后按TAB键。 (按Ctrl-Alt也会清除福彩12选5走势图)。

我刚刚发现了一些其他信息。仅当将SlateBlue PictureBox中没有福彩12选5走势图时,将福彩12选5走势图从PictureBox放到SlateBlue PictureBox中之后,才发生这种情况。如果在已有另一个福彩12选5走势图后,将其放置在SlateBlue PictureBox上,则TAB键不会清除该福彩12选5走势图。真是奇怪的行为。

1608744487027.png


我也只是尝试在SlateBlue PictureBox中设置初始福彩12选5走势图,而TAB键仍然删除了掉落的福彩12选5走势图...

1608747311015.png
 
Last edited:

tim8w

知名会员
已加入
2020年9月8日
留言内容
61
编程经验
10+
如果没有看到您的代码以及如何处理各种事件,我们只是在推测。
天空,
这里是:
C#:
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 SQLQueryBuilder
{
    public partial class frmCriteria : Form
    {
        public string sSQLQuery = "WHERE ";
        private string sSelectedCommand1 = "";
        private string sBaseQuery = "";

        public frmCriteria()
        {
            InitializeComponent();
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            System.Drawing.Drawing2D.LinearGradientBrush gradientBrush = new System.Drawing.Drawing2D.LinearGradientBrush(this.ClientRectangle, Color.Black, Color.SteelBlue, 90);

            e.Graphics.FillRectangle(gradientBrush, this.ClientRectangle);
        }

        private void frmCriteria_Load(object sender, EventArgs e)
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            this.UpdateStyles();

            this.Text = "Crieria Builder for " + frmSQLQueryBuilder.sQueryField;
            this.sBaseQuery = "WHERE " + frmSQLQueryBuilder.sQueryField;

            this.pbLessThan.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbLessThan_MouseDown);
            this.pbLessThanEqual.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbLessThanEqual_MouseDown);
            this.pbEqual.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbEqual_MouseDown);
            this.pbGreaterThanEqual.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbGreaterThanEqual_MouseDown);
            this.pbGreaterThan.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbGreaterThan_MouseDown);
            this.pbAnd.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbAnd_MouseDown);
            this.pbBetween.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbBetween_MouseDown);
            this.pbLike.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pbLike_MouseDown);

            this.pbCommand1.AllowDrop = true;
            this.pbCommand2.AllowDrop = true;
            this.pbCommand1.DragDrop += new System.Windows.Forms.DragEventHandler(this.pbCommand1_DragDrop);
            this.pbCommand1.DragEnter += new System.Windows.Forms.DragEventHandler(this.pbCommand1_DragEnter);

            lblField.Text = frmSQLQueryBuilder.sQueryField;
            switch (frmSQLQueryBuilder.sQueryField)
            {
                case "Date":
                    txtLesserNum.Visible = false;
                    txtGreaterNum.Visible = false;
                    dtStartDateTime.Visible = true;
                    dtEndDateTime.Visible = false;
                    pbLike.Enabled = false;
                    pbLike.Image = SQLQueryBuilder.Properties.Resources.LikeGrey64;
                    break;
                default:
                    txtLesserNum.Visible = true;
                    txtGreaterNum.Visible = false;
                    dtStartDateTime.Visible = false;
                    dtEndDateTime.Visible = false;
                    break;
            }
            pbAnd.Enabled = false;
            pbAnd.Image = SQLQueryBuilder.Properties.Resources.PlusGrey64;
            lblSQLQueryString.Text = sBaseQuery;
        }

        private void pbLessThan_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pbSelected = (PictureBox)sender;
            sSelectedCommand1 = "Less Than";
            pbSelected.DoDragDrop(pbSelected.Image, DragDropEffects.Copy);
        }

        private void pbLessThanEqual_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pbSelected = (PictureBox)sender;
            sSelectedCommand1 = "Less Than or Equal";
            pbSelected.DoDragDrop(pbSelected.Image, DragDropEffects.Copy);
        }

        private void pbEqual_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pbSelected = (PictureBox)sender;
            sSelectedCommand1 = "Equal";
            pbSelected.DoDragDrop(pbSelected.Image, DragDropEffects.Copy);
        }

        private void pbGreaterThanEqual_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pbSelected = (PictureBox)sender;
            sSelectedCommand1 = "Greater Than or Equal";
            pbSelected.DoDragDrop(pbSelected.Image, DragDropEffects.Copy);
        }

        private void pbGreaterThan_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pbSelected = (PictureBox)sender;
            sSelectedCommand1 = "Greater Than";
            pbSelected.DoDragDrop(pbSelected.Image, DragDropEffects.Copy);
        }

        private void pbAnd_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pbSelected = (PictureBox)sender;
            sSelectedCommand1 = "And";
            pbSelected.DoDragDrop(pbSelected.Image, DragDropEffects.Copy);
        }

        private void pbBetween_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pbSelected = (PictureBox)sender;
            sSelectedCommand1 = "Between";
            pbSelected.DoDragDrop(pbSelected.Image, DragDropEffects.Copy);
        }

        private void pbLike_MouseDown(object sender, MouseEventArgs e)
        {
            PictureBox pbSelected = (PictureBox)sender;
            sSelectedCommand1 = "Like";
            pbSelected.DoDragDrop(pbSelected.Image, DragDropEffects.Copy);
        }

        private void pbCommand1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Bitmap))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void pbCommand2_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Bitmap))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void pbCommand1_DragDrop(object sender, DragEventArgs e)
        {
            PictureBox picbox = (PictureBox)sender;
            Graphics g = picbox.CreateGraphics();
            g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap), new Point(0, 0));
            lblCommand1.Text = sSelectedCommand1;

            switch (frmSQLQueryBuilder.sQueryField)
            {
                case "Date":
                    txtGreaterNum.Visible = false;
                    pbAnd.Enabled = false;
                    pbAnd.Image = SQLQueryBuilder.Properties.Resources.PlusGrey64;
                    pbCommand2.Visible = false;
                    lblCommand2.Visible = false;
                    dtEndDateTime.Visible = false;
                    switch(sSelectedCommand1)
                    {
                        case "Less Than":
                            lblSQLQueryString.Text = sBaseQuery + " < '" + dtStartDateTime.Text + "' ";
                            break;
                        case "Less Than or Equal":
                            lblSQLQueryString.Text = sBaseQuery + " <= '" + dtStartDateTime.Text + "' ";
                            break;
                        case "Equal":
                            lblSQLQueryString.Text = sBaseQuery + " = '" + dtStartDateTime.Text + "' ";
                            break;
                        case "Greater Than or Equal":
                            lblSQLQueryString.Text = sBaseQuery + " >= '" + dtStartDateTime.Text + "' ";
                            break;
                        case "Greater Than":
                            lblSQLQueryString.Text = sBaseQuery + " > '" + dtStartDateTime.Text + "' ";
                            break;
                        case "Between":
                            pbCommand2.Visible = true;
                            lblCommand2.Visible = true;
                            dtEndDateTime.Visible = true;
                            lblCommand2.Text = "And";
                            pbCommand2.Image = SQLQueryBuilder.Properties.Resources.Plus64;
                            lblSQLQueryString.Text = sBaseQuery + " BETWEEN '" + dtStartDateTime.Text + "' AND '" + dtEndDateTime.Text + "' ";
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    pbCommand2.Visible = false;
                    txtGreaterNum.Visible = false;
                    dtEndDateTime.Visible = false;
                    lblCommand2.Visible = false;
                    pbAnd.Enabled = false;
                    pbAnd.Image = SQLQueryBuilder.Properties.Resources.PlusGrey64;
                    switch(sSelectedCommand1)
                    {
                        case "Less Than":
                            lblSQLQueryString.Text = sBaseQuery + " < '" + txtLesserNum.Text + "' ";
                            break;
                        case "Less Than or Equal":
                            lblSQLQueryString.Text = sBaseQuery + " <= '" + txtLesserNum.Text + "' ";
                            break;
                        case "Equal":
                            lblSQLQueryString.Text = sBaseQuery + " = '" + txtLesserNum.Text + "' ";
                            break;
                        case "Greater Than or Equal":
                            lblSQLQueryString.Text = sBaseQuery + " >= '" + txtLesserNum.Text + "' ";
                            break;
                        case "Greater Than":
                            lblSQLQueryString.Text = sBaseQuery + " > '" + txtLesserNum.Text + "' ";
                            break;
                        case "Between":
                            pbCommand2.Visible = true;
                            lblCommand2.Visible = true;
                            lblCommand2.Text = "And";
                            txtGreaterNum.Visible = true;
                            pbCommand2.Image = SQLQueryBuilder.Properties.Resources.Plus64;
                            lblSQLQueryString.Text = sBaseQuery + " BETWEEN '" + txtLesserNum.Text + "' AND '" + txtGreaterNum.Text + "' ";
                            break;
                        case "Like":
                            lblSQLQueryString.Text = sBaseQuery + " LIKE '%" + txtLesserNum.Text + "%' ";
                            break;
                    }
                    break;
            }
        }

        private void ttControl_Draw(object sender, DrawToolTipEventArgs e)
        {
            Font tooltipFont = new Font("Microsoft Sans Serif", 10.8f, FontStyle.Bold);
            e.DrawBackground();
            e.DrawBorder();
            e.Graphics.DrawString(e.ToolTipText, tooltipFont, Brushes.Black, new PointF(4, 2));
        }

        private void ttControl_Popup(object sender, PopupEventArgs e)
        {
            Size newSize;
            newSize = TextRenderer.MeasureText(ttControl.GetToolTip(e.AssociatedControl), new Font("Microsoft Sans Serif", 10.8f, FontStyle.Bold), new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding);
            newSize = new Size(newSize.Width, newSize.Height + 6);
            e.ToolTipSize = newSize;
        }

        private void txtLesserNum_TextChanged(object sender, EventArgs e)
        {
            switch (sSelectedCommand1)
            {
                case "Less Than":
                    lblSQLQueryString.Text = sBaseQuery + " < '" + txtLesserNum.Text + "' ";
                    break;
                case "Less Than or Equal":
                    lblSQLQueryString.Text = sBaseQuery + " <= '" + txtLesserNum.Text + "' ";
                    break;
                case "Equal":
                    lblSQLQueryString.Text = sBaseQuery + " = '" + txtLesserNum.Text + "' ";
                    break;
                case "Greater Than or Equal":
                    lblSQLQueryString.Text = sBaseQuery + " >= '" + txtLesserNum.Text + "' ";
                    break;
                case "Greater Than":
                    lblSQLQueryString.Text = sBaseQuery + " > '" + txtLesserNum.Text + "' ";
                    break;
                case "Between":
                    lblSQLQueryString.Text = sBaseQuery + " BETWEEN '" + txtLesserNum.Text + "' ";
                    break;
                case "Like":
                    lblSQLQueryString.Text = sBaseQuery + " LIKE '%" + txtLesserNum.Text + "%' ";
                    break;
            }
        }

        private void txtGreaterNum_TextChanged(object sender, EventArgs e)
        {
            lblSQLQueryString.Text = sBaseQuery + " BETWEEN '" + txtLesserNum.Text + "' AND '" + txtGreaterNum.Text + "' ";
        }
    }
}
 

tim8w

知名会员
已加入
2020年9月8日
留言内容
61
编程经验
10+
您必须设置Image或使用Paint事件进行绘制。使用CreateGraphics不会持久,因为任何原因重新绘制控件时都会擦除它。
约翰,
设置PictureBox福彩12选5走势图就像一个魅力!

C#:
PictureBox picbox = (PictureBox)sender;
picbox.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
 
最佳 底部