Click here to Skip to main content
15,902,893 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am m using DrawReversibleFrame to draw a rectangle with inverse colors based on mouse position over a control.
I have written my code in picturebox_Mousemove event
Its working perfectly, rectangle is drawn when i move my mouse and draw accordingly but when i hold my left mouse Button for a while it(rubberband) dissapear and again when i move it is visible .why is it so??? or because i have written it in MouseMove event if so is there another solution,
my second question is why the frame is doubled?
Posted
Updated 13-Jan-15 1:29am
v2
Comments
LLLLGGGG 13-Jan-15 12:02pm    
It can be REALLY useful to have a piece of your code... the one with the problem obiviously. ☆

LG
Member 11000455 16-Jan-15 4:07am    
private int m_iMouseX = -1;
private int m_iMouseY = -1;
private string sToolTipLabelText = string.Empty;
private Rectangle m_oCtlRubberband = new Rectangle(-1, -1, 0, 0);


private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{

try
{
if ((pictureBox1.Image != null) &&
(m_oCurrSelNode != null) &&
(m_oCurrSelNode.Tag as ControlDefinition != null))
{
if (e.Button == MouseButtons.Left &&
m_oCtlRubberband.X > 0 && m_oCtlRubberband.Y > 0) // rubberband started?
{
// remove old rubberband
Rectangle screenRubberband = pictureBox1.RectangleToScreen(m_oCtlRubberband);
Color rubberbandColor = m_clrFieldRubberband;
if (pictureBox1.TextDetectionMode)
{
rubberbandColor = m_clrOcrRubberband;
}
ControlPaint.DrawReversibleFrame(screenRubberband, rubberbandColor, FrameStyle.Dashed);


// clip new rubberband within the picture box only
m_oCtlRubberband.Width = Math.Max(Math.Min(e.X, pictureBox1.Width), 0) - m_oCtlRubberband.X;
m_oCtlRubberband.Height = Math.Max(Math.Min(e.Y, pictureBox1.Height), 0) - m_oCtlRubberband.Y;

screenRubberband = pictureBox1.RectangleToScreen(m_oCtlRubberband);
ControlPaint.DrawReversibleFrame(screenRubberband, rubberbandColor, FrameStyle.Dashed);

// String leveltext ;

if (e.X != m_iMouseX || e.Y != m_iMouseY)
{
// update status label
bool showSize = true;
ControlDefinition oCtrl = m_oCurrSelNode.Tag as ControlDefinition;
if (oCtrl.GetType() == typeof(HandwrittenAnswer))
{
HandwrittenAnswer oCb = (HandwrittenAnsweroCtrl;
if (oCb.DetectionMode == HandwrittenAnswer.Automatic)
{
showSize = false;
}
}

if (showSize)
{
//
int iWidth = Math.Abs((int)(m_oCtlRubberband.Width * pictureBox1.ScaleX));
int iHeight = Math.Abs((int)(m_oCtlRubberband.Height * pictureBox1.ScaleY));

sLabelText = String.Format(Properties.Resources.MsgImageRubberband, iWidth, iHeight);
}
else
{
sToolTipLabelText = Properties.Resources.ContextMenuItemCheckboxDetectionMode;
}
toolStripStatusLabel2.Text = sToolTipLabelText;
}
}

}
}
catch (System.Exception ex)
{
//here shows exception
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900