Movable FrameControl in Picturebox not working as intendedCreating Custom Picturebox with Draggable and Resizable Selection WindowAdd Generic list in a MyClass but how?C# File.Delete, file being used by another processHow can I create GDI Leaks in Windows Forms!How to kill an alert window in Windows using C#?Adding Controls to Form from another classCoordinate Mismatch ProblemWebBrowser Control DocumentCompleted after iframe & Javascript completionVisual C# Programming a Login form connected to a Access Db that gives only tries to log intoC# method failing to function for no known reasonArray of textbox and labels how to get value in submit method in c#

My bank got bought out, am I now going to have to start filing tax returns in a different state?

How to pronounce 'c++' in Spanish

Mistake in years of experience in resume?

Island of Knights, Knaves and Spies

Older movie/show about humans on derelict alien warship which refuels by passing through a star

How to not starve gigantic beasts

Is there any pythonic way to find average of specific tuple elements in array?

Can a stored procedure reference the database in which it is stored?

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

A ​Note ​on ​N!

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Which big number is bigger?

How can I practically buy stocks?

Restricting the options of a lookup field, based on the value of another lookup field?

Is it acceptable to use working hours to read general interest books?

How much cash can I safely carry into the USA and avoid civil forfeiture?

As an international instructor, should I openly talk about my accent?

Is there really no use for MD5 anymore?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

What *exactly* is electrical current, voltage, and resistance?

Multiple options vs single option UI

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

Find the identical rows in a matrix

Is Electric Central Heating worth it if using Solar Panels?



Movable FrameControl in Picturebox not working as intended


Creating Custom Picturebox with Draggable and Resizable Selection WindowAdd Generic list in a MyClass but how?C# File.Delete, file being used by another processHow can I create GDI Leaks in Windows Forms!How to kill an alert window in Windows using C#?Adding Controls to Form from another classCoordinate Mismatch ProblemWebBrowser Control DocumentCompleted after iframe & Javascript completionVisual C# Programming a Login form connected to a Access Db that gives only tries to log intoC# method failing to function for no known reasonArray of textbox and labels how to get value in submit method in c#






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I'm using the following code to add a movable Frame control to a picturebox and add a translucent background to the outer area of the frame.But the black translucent color is not appearing outside the frame as intended.It is supposed to fill up all the area outside the frame.On dragging the frame its producing the black area where its dragged.



I'm using a picturebox with size mode set to Zoom.
enter image description here



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

namespace DXApplication5

public partial class Form1 : DevExpress.XtraEditors.XtraForm

public Form1()

InitializeComponent();
pictureBox1.Paint += PictureBox1_Paint;


private void PictureBox1_Paint(object sender, PaintEventArgs e)

if (pictureBox1.Controls.Count > 0)

e.Graphics.ExcludeClip(pictureBox1.Controls[0].Bounds);
using (var b = new SolidBrush(Color.FromArgb(100, Color.Black)))
e.Graphics.FillRectangle(b, pictureBox1.ClientRectangle);



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);


private void Form1_Load(object sender, EventArgs e)





public class FrameControl : Control

public FrameControl()

SetStyle(ControlStyles.SupportsTransparentBackColor, true);
DoubleBuffered = true;
ResizeRedraw = true;
BackColor = Color.Transparent;

protected override void OnPaint(PaintEventArgs e)

base.OnPaint(e);
using (var p = new Pen(Color.Black, 4))

p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawRectangle(p, 0, 0, Width - 1, Height - 1);


const int WM_NCHITTEST = 0x84;
const int WM_SETCURSOR = 0x20;
const int WM_NCLBUTTONDBLCLK = 0xA3;
protected override void WndProc(ref Message m)

int borderWidth = 10;
if (m.Msg == WM_SETCURSOR) /*Setting cursor to SizeAll*/

if ((m.LParam.ToInt32() & 0xffff) == 0x2 /*Move*/)

Cursor.Current = Cursors.SizeAll;
m.Result = (IntPtr)1;
return;


if ((m.Msg == WM_NCLBUTTONDBLCLK)) /*Disable Mazimiz on Double click*/

m.Result = (IntPtr)1;
return;

base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)

var pos = PointToClient(new Point(m.LParam.ToInt32() & 0xffff,
m.LParam.ToInt32() >> 16));
if (pos.X <= ClientRectangle.Left + borderWidth &&
pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(13); //TOPLEFT
else if (pos.X >= ClientRectangle.Right - borderWidth &&
pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(14); //TOPRIGHT
else if (pos.X <= ClientRectangle.Left + borderWidth &&
pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(16); //BOTTOMLEFT
else if (pos.X >= ClientRectangle.Right - borderWidth &&
pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(17); //BOTTOMRIGHT
else if (pos.X <= ClientRectangle.Left + borderWidth)
m.Result = new IntPtr(10); //LEFT
else if (pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(12); //TOP
else if (pos.X >= ClientRectangle.Right - borderWidth)
m.Result = new IntPtr(11); //RIGHT
else if (pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(15); //Bottom
else
m.Result = new IntPtr(2); //Move













share|improve this question
























  • Please define “not working as intended”

    – Sami Kuhmonen
    Mar 9 at 7:30











  • @SamiKuhmonen Please see the update.

    – techno
    Mar 9 at 7:41











  • Is it all code to reproduce the problem? I couldn't reproduce it.

    – Reza Aghaei
    Mar 9 at 19:06












  • It seems the issue is not relevant to the frame. Replace pictureBox1.Controls[0].Bounds with a rectangle to see the result.

    – Reza Aghaei
    Mar 9 at 19:16











  • @RezaAghaei Yes.Have you tried dragging the frame ?

    – techno
    Mar 9 at 19:17

















2















I'm using the following code to add a movable Frame control to a picturebox and add a translucent background to the outer area of the frame.But the black translucent color is not appearing outside the frame as intended.It is supposed to fill up all the area outside the frame.On dragging the frame its producing the black area where its dragged.



I'm using a picturebox with size mode set to Zoom.
enter image description here



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

namespace DXApplication5

public partial class Form1 : DevExpress.XtraEditors.XtraForm

public Form1()

InitializeComponent();
pictureBox1.Paint += PictureBox1_Paint;


private void PictureBox1_Paint(object sender, PaintEventArgs e)

if (pictureBox1.Controls.Count > 0)

e.Graphics.ExcludeClip(pictureBox1.Controls[0].Bounds);
using (var b = new SolidBrush(Color.FromArgb(100, Color.Black)))
e.Graphics.FillRectangle(b, pictureBox1.ClientRectangle);



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);


private void Form1_Load(object sender, EventArgs e)





public class FrameControl : Control

public FrameControl()

SetStyle(ControlStyles.SupportsTransparentBackColor, true);
DoubleBuffered = true;
ResizeRedraw = true;
BackColor = Color.Transparent;

protected override void OnPaint(PaintEventArgs e)

base.OnPaint(e);
using (var p = new Pen(Color.Black, 4))

p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawRectangle(p, 0, 0, Width - 1, Height - 1);


const int WM_NCHITTEST = 0x84;
const int WM_SETCURSOR = 0x20;
const int WM_NCLBUTTONDBLCLK = 0xA3;
protected override void WndProc(ref Message m)

int borderWidth = 10;
if (m.Msg == WM_SETCURSOR) /*Setting cursor to SizeAll*/

if ((m.LParam.ToInt32() & 0xffff) == 0x2 /*Move*/)

Cursor.Current = Cursors.SizeAll;
m.Result = (IntPtr)1;
return;


if ((m.Msg == WM_NCLBUTTONDBLCLK)) /*Disable Mazimiz on Double click*/

m.Result = (IntPtr)1;
return;

base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)

var pos = PointToClient(new Point(m.LParam.ToInt32() & 0xffff,
m.LParam.ToInt32() >> 16));
if (pos.X <= ClientRectangle.Left + borderWidth &&
pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(13); //TOPLEFT
else if (pos.X >= ClientRectangle.Right - borderWidth &&
pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(14); //TOPRIGHT
else if (pos.X <= ClientRectangle.Left + borderWidth &&
pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(16); //BOTTOMLEFT
else if (pos.X >= ClientRectangle.Right - borderWidth &&
pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(17); //BOTTOMRIGHT
else if (pos.X <= ClientRectangle.Left + borderWidth)
m.Result = new IntPtr(10); //LEFT
else if (pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(12); //TOP
else if (pos.X >= ClientRectangle.Right - borderWidth)
m.Result = new IntPtr(11); //RIGHT
else if (pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(15); //Bottom
else
m.Result = new IntPtr(2); //Move













share|improve this question
























  • Please define “not working as intended”

    – Sami Kuhmonen
    Mar 9 at 7:30











  • @SamiKuhmonen Please see the update.

    – techno
    Mar 9 at 7:41











  • Is it all code to reproduce the problem? I couldn't reproduce it.

    – Reza Aghaei
    Mar 9 at 19:06












  • It seems the issue is not relevant to the frame. Replace pictureBox1.Controls[0].Bounds with a rectangle to see the result.

    – Reza Aghaei
    Mar 9 at 19:16











  • @RezaAghaei Yes.Have you tried dragging the frame ?

    – techno
    Mar 9 at 19:17













2












2








2








I'm using the following code to add a movable Frame control to a picturebox and add a translucent background to the outer area of the frame.But the black translucent color is not appearing outside the frame as intended.It is supposed to fill up all the area outside the frame.On dragging the frame its producing the black area where its dragged.



I'm using a picturebox with size mode set to Zoom.
enter image description here



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

namespace DXApplication5

public partial class Form1 : DevExpress.XtraEditors.XtraForm

public Form1()

InitializeComponent();
pictureBox1.Paint += PictureBox1_Paint;


private void PictureBox1_Paint(object sender, PaintEventArgs e)

if (pictureBox1.Controls.Count > 0)

e.Graphics.ExcludeClip(pictureBox1.Controls[0].Bounds);
using (var b = new SolidBrush(Color.FromArgb(100, Color.Black)))
e.Graphics.FillRectangle(b, pictureBox1.ClientRectangle);



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);


private void Form1_Load(object sender, EventArgs e)





public class FrameControl : Control

public FrameControl()

SetStyle(ControlStyles.SupportsTransparentBackColor, true);
DoubleBuffered = true;
ResizeRedraw = true;
BackColor = Color.Transparent;

protected override void OnPaint(PaintEventArgs e)

base.OnPaint(e);
using (var p = new Pen(Color.Black, 4))

p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawRectangle(p, 0, 0, Width - 1, Height - 1);


const int WM_NCHITTEST = 0x84;
const int WM_SETCURSOR = 0x20;
const int WM_NCLBUTTONDBLCLK = 0xA3;
protected override void WndProc(ref Message m)

int borderWidth = 10;
if (m.Msg == WM_SETCURSOR) /*Setting cursor to SizeAll*/

if ((m.LParam.ToInt32() & 0xffff) == 0x2 /*Move*/)

Cursor.Current = Cursors.SizeAll;
m.Result = (IntPtr)1;
return;


if ((m.Msg == WM_NCLBUTTONDBLCLK)) /*Disable Mazimiz on Double click*/

m.Result = (IntPtr)1;
return;

base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)

var pos = PointToClient(new Point(m.LParam.ToInt32() & 0xffff,
m.LParam.ToInt32() >> 16));
if (pos.X <= ClientRectangle.Left + borderWidth &&
pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(13); //TOPLEFT
else if (pos.X >= ClientRectangle.Right - borderWidth &&
pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(14); //TOPRIGHT
else if (pos.X <= ClientRectangle.Left + borderWidth &&
pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(16); //BOTTOMLEFT
else if (pos.X >= ClientRectangle.Right - borderWidth &&
pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(17); //BOTTOMRIGHT
else if (pos.X <= ClientRectangle.Left + borderWidth)
m.Result = new IntPtr(10); //LEFT
else if (pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(12); //TOP
else if (pos.X >= ClientRectangle.Right - borderWidth)
m.Result = new IntPtr(11); //RIGHT
else if (pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(15); //Bottom
else
m.Result = new IntPtr(2); //Move













share|improve this question
















I'm using the following code to add a movable Frame control to a picturebox and add a translucent background to the outer area of the frame.But the black translucent color is not appearing outside the frame as intended.It is supposed to fill up all the area outside the frame.On dragging the frame its producing the black area where its dragged.



I'm using a picturebox with size mode set to Zoom.
enter image description here



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

namespace DXApplication5

public partial class Form1 : DevExpress.XtraEditors.XtraForm

public Form1()

InitializeComponent();
pictureBox1.Paint += PictureBox1_Paint;


private void PictureBox1_Paint(object sender, PaintEventArgs e)

if (pictureBox1.Controls.Count > 0)

e.Graphics.ExcludeClip(pictureBox1.Controls[0].Bounds);
using (var b = new SolidBrush(Color.FromArgb(100, Color.Black)))
e.Graphics.FillRectangle(b, pictureBox1.ClientRectangle);



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);


private void Form1_Load(object sender, EventArgs e)





public class FrameControl : Control

public FrameControl()

SetStyle(ControlStyles.SupportsTransparentBackColor, true);
DoubleBuffered = true;
ResizeRedraw = true;
BackColor = Color.Transparent;

protected override void OnPaint(PaintEventArgs e)

base.OnPaint(e);
using (var p = new Pen(Color.Black, 4))

p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawRectangle(p, 0, 0, Width - 1, Height - 1);


const int WM_NCHITTEST = 0x84;
const int WM_SETCURSOR = 0x20;
const int WM_NCLBUTTONDBLCLK = 0xA3;
protected override void WndProc(ref Message m)

int borderWidth = 10;
if (m.Msg == WM_SETCURSOR) /*Setting cursor to SizeAll*/

if ((m.LParam.ToInt32() & 0xffff) == 0x2 /*Move*/)

Cursor.Current = Cursors.SizeAll;
m.Result = (IntPtr)1;
return;


if ((m.Msg == WM_NCLBUTTONDBLCLK)) /*Disable Mazimiz on Double click*/

m.Result = (IntPtr)1;
return;

base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)

var pos = PointToClient(new Point(m.LParam.ToInt32() & 0xffff,
m.LParam.ToInt32() >> 16));
if (pos.X <= ClientRectangle.Left + borderWidth &&
pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(13); //TOPLEFT
else if (pos.X >= ClientRectangle.Right - borderWidth &&
pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(14); //TOPRIGHT
else if (pos.X <= ClientRectangle.Left + borderWidth &&
pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(16); //BOTTOMLEFT
else if (pos.X >= ClientRectangle.Right - borderWidth &&
pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(17); //BOTTOMRIGHT
else if (pos.X <= ClientRectangle.Left + borderWidth)
m.Result = new IntPtr(10); //LEFT
else if (pos.Y <= ClientRectangle.Top + borderWidth)
m.Result = new IntPtr(12); //TOP
else if (pos.X >= ClientRectangle.Right - borderWidth)
m.Result = new IntPtr(11); //RIGHT
else if (pos.Y >= ClientRectangle.Bottom - borderWidth)
m.Result = new IntPtr(15); //Bottom
else
m.Result = new IntPtr(2); //Move










c# .net winforms custom-controls gdi+






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 at 7:13









Reza Aghaei

69.6k861181




69.6k861181










asked Mar 9 at 7:11









technotechno

1,8721148105




1,8721148105












  • Please define “not working as intended”

    – Sami Kuhmonen
    Mar 9 at 7:30











  • @SamiKuhmonen Please see the update.

    – techno
    Mar 9 at 7:41











  • Is it all code to reproduce the problem? I couldn't reproduce it.

    – Reza Aghaei
    Mar 9 at 19:06












  • It seems the issue is not relevant to the frame. Replace pictureBox1.Controls[0].Bounds with a rectangle to see the result.

    – Reza Aghaei
    Mar 9 at 19:16











  • @RezaAghaei Yes.Have you tried dragging the frame ?

    – techno
    Mar 9 at 19:17

















  • Please define “not working as intended”

    – Sami Kuhmonen
    Mar 9 at 7:30











  • @SamiKuhmonen Please see the update.

    – techno
    Mar 9 at 7:41











  • Is it all code to reproduce the problem? I couldn't reproduce it.

    – Reza Aghaei
    Mar 9 at 19:06












  • It seems the issue is not relevant to the frame. Replace pictureBox1.Controls[0].Bounds with a rectangle to see the result.

    – Reza Aghaei
    Mar 9 at 19:16











  • @RezaAghaei Yes.Have you tried dragging the frame ?

    – techno
    Mar 9 at 19:17
















Please define “not working as intended”

– Sami Kuhmonen
Mar 9 at 7:30





Please define “not working as intended”

– Sami Kuhmonen
Mar 9 at 7:30













@SamiKuhmonen Please see the update.

– techno
Mar 9 at 7:41





@SamiKuhmonen Please see the update.

– techno
Mar 9 at 7:41













Is it all code to reproduce the problem? I couldn't reproduce it.

– Reza Aghaei
Mar 9 at 19:06






Is it all code to reproduce the problem? I couldn't reproduce it.

– Reza Aghaei
Mar 9 at 19:06














It seems the issue is not relevant to the frame. Replace pictureBox1.Controls[0].Bounds with a rectangle to see the result.

– Reza Aghaei
Mar 9 at 19:16





It seems the issue is not relevant to the frame. Replace pictureBox1.Controls[0].Bounds with a rectangle to see the result.

– Reza Aghaei
Mar 9 at 19:16













@RezaAghaei Yes.Have you tried dragging the frame ?

– techno
Mar 9 at 19:17





@RezaAghaei Yes.Have you tried dragging the frame ?

– techno
Mar 9 at 19:17












1 Answer
1






active

oldest

votes


















1














PicturBox just paints those part of the control which need repaint. Since have added the control at run-time after the picture box get visible, you need to invalidate picture box after adding FrameControl to repaint the entire control.



Consider calling Invalidate method of the parent of FrameControl when you add or remove it from the parent or when you change visibility of the control.



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);
c.VisibleChanged
pictureBox1.Invalidate();






share|improve this answer

























  • Thanks a lot,this solved the issue.Let me try updating the main project.

    – techno
    Mar 10 at 6:56











  • It works fine... Thanks for your effort.

    – techno
    Mar 10 at 7:10











  • You're welcome :)

    – Reza Aghaei
    Mar 10 at 7:11











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074941%2fmovable-framecontrol-in-picturebox-not-working-as-intended%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














PicturBox just paints those part of the control which need repaint. Since have added the control at run-time after the picture box get visible, you need to invalidate picture box after adding FrameControl to repaint the entire control.



Consider calling Invalidate method of the parent of FrameControl when you add or remove it from the parent or when you change visibility of the control.



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);
c.VisibleChanged
pictureBox1.Invalidate();






share|improve this answer

























  • Thanks a lot,this solved the issue.Let me try updating the main project.

    – techno
    Mar 10 at 6:56











  • It works fine... Thanks for your effort.

    – techno
    Mar 10 at 7:10











  • You're welcome :)

    – Reza Aghaei
    Mar 10 at 7:11















1














PicturBox just paints those part of the control which need repaint. Since have added the control at run-time after the picture box get visible, you need to invalidate picture box after adding FrameControl to repaint the entire control.



Consider calling Invalidate method of the parent of FrameControl when you add or remove it from the parent or when you change visibility of the control.



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);
c.VisibleChanged
pictureBox1.Invalidate();






share|improve this answer

























  • Thanks a lot,this solved the issue.Let me try updating the main project.

    – techno
    Mar 10 at 6:56











  • It works fine... Thanks for your effort.

    – techno
    Mar 10 at 7:10











  • You're welcome :)

    – Reza Aghaei
    Mar 10 at 7:11













1












1








1







PicturBox just paints those part of the control which need repaint. Since have added the control at run-time after the picture box get visible, you need to invalidate picture box after adding FrameControl to repaint the entire control.



Consider calling Invalidate method of the parent of FrameControl when you add or remove it from the parent or when you change visibility of the control.



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);
c.VisibleChanged
pictureBox1.Invalidate();






share|improve this answer















PicturBox just paints those part of the control which need repaint. Since have added the control at run-time after the picture box get visible, you need to invalidate picture box after adding FrameControl to repaint the entire control.



Consider calling Invalidate method of the parent of FrameControl when you add or remove it from the parent or when you change visibility of the control.



private void button1_Click(object sender, EventArgs e)

var s = 300;
var c = new FrameControl();
c.Size = new Size(s, s);
c.Location = new Point((pictureBox1.Width - s) / 2, (pictureBox1.Height - s) / 2);
pictureBox1.Controls.Add(c);
c.VisibleChanged
pictureBox1.Invalidate();







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 10 at 6:55

























answered Mar 10 at 6:42









Reza AghaeiReza Aghaei

69.6k861181




69.6k861181












  • Thanks a lot,this solved the issue.Let me try updating the main project.

    – techno
    Mar 10 at 6:56











  • It works fine... Thanks for your effort.

    – techno
    Mar 10 at 7:10











  • You're welcome :)

    – Reza Aghaei
    Mar 10 at 7:11

















  • Thanks a lot,this solved the issue.Let me try updating the main project.

    – techno
    Mar 10 at 6:56











  • It works fine... Thanks for your effort.

    – techno
    Mar 10 at 7:10











  • You're welcome :)

    – Reza Aghaei
    Mar 10 at 7:11
















Thanks a lot,this solved the issue.Let me try updating the main project.

– techno
Mar 10 at 6:56





Thanks a lot,this solved the issue.Let me try updating the main project.

– techno
Mar 10 at 6:56













It works fine... Thanks for your effort.

– techno
Mar 10 at 7:10





It works fine... Thanks for your effort.

– techno
Mar 10 at 7:10













You're welcome :)

– Reza Aghaei
Mar 10 at 7:11





You're welcome :)

– Reza Aghaei
Mar 10 at 7:11



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074941%2fmovable-framecontrol-in-picturebox-not-working-as-intended%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович