Click here to Skip to main content
15,923,789 members
Home / Discussions / C#
   

C#

 
AnswerRe: Memory expensive rubber band selection? Pin
Luc Pattyn1-Jun-11 0:42
sitebuilderLuc Pattyn1-Jun-11 0:42 
GeneralRe: Memory expensive rubber band selection? Pin
Chesnokov Yuriy1-Jun-11 0:56
professionalChesnokov Yuriy1-Jun-11 0:56 
AnswerRe: Memory expensive rubber band selection? Pin
Eddy Vluggen1-Jun-11 1:00
professionalEddy Vluggen1-Jun-11 1:00 
GeneralRe: Memory expensive rubber band selection? Pin
BobJanova1-Jun-11 1:24
BobJanova1-Jun-11 1:24 
GeneralRe: Memory expensive rubber band selection? Pin
Pete O'Hanlon1-Jun-11 1:41
mvePete O'Hanlon1-Jun-11 1:41 
AnswerRe: Memory expensive rubber band selection? Pin
Luc Pattyn1-Jun-11 1:41
sitebuilderLuc Pattyn1-Jun-11 1:41 
QuestionRe: Memory expensive rubber band selection? Pin
Chesnokov Yuriy1-Jun-11 1:56
professionalChesnokov Yuriy1-Jun-11 1:56 
AnswerRe: Memory expensive rubber band selection? Pin
_Erik_1-Jun-11 3:47
_Erik_1-Jun-11 3:47 
What I understand is that you are trying to darken a rectangle within a image, and that rectangle must be refreshed as long as the mouse is moving. Am I right?

If this is what you want to do, the problem is that you are creating too many new Graphics and Bitmap objects in a very short time (and these are expensive objects), and updating the Image property a lot of times as well. The best way to do it is to subscribe to the Paint event of the control and code everything in this event handler, so you will receive a Graphics object as a parameter. In the next example there is only a PictureBox in the Form, called pct:

C#
public partial class Form1 : Form
{
    bool drawRect = false;
    Rectangle r = new Rectangle();
    Brush br = new SolidBrush(Color.FromArgb(50, Color.Red));

    public Form1()
    {
        InitializeComponent();
    }

    private void pct_Paint(object sender, PaintEventArgs e)
    {
        if (drawRect)
            e.Graphics.FillRectangle(br, r);
    }

    private void pct_MouseDown(object sender, MouseEventArgs e)
    {
        drawRect = true;
        r.X = e.X;
        r.Y = e.Y;
    }

    private void pct_MouseMove(object sender, MouseEventArgs e)
    {
        r.Width = e.X - r.X;
        r.Height = e.Y - r.Y;

        Refresh();
    }

    private void pct_MouseUp(object sender, MouseEventArgs e)
    {
        drawRect = false;
        Refresh();
    }
}


I've made it quick. You would have to modify it in order to draw the rectangle if the mouse moves to a lower X and/or lower Y coordinate.
GeneralRe: Memory expensive rubber band selection? Pin
Chesnokov Yuriy1-Jun-11 7:18
professionalChesnokov Yuriy1-Jun-11 7:18 
GeneralRe: Memory expensive rubber band selection? Pin
_Erik_2-Jun-11 1:51
_Erik_2-Jun-11 1:51 
QuestionWork with Geotiff in C# Pin
Reza Shojaee31-May-11 22:04
Reza Shojaee31-May-11 22:04 
AnswerRe: Work with Geotiff in C# Pin
Pete O'Hanlon31-May-11 22:32
mvePete O'Hanlon31-May-11 22:32 
Questionabstarct class basic question [modified] Pin
PozzaVecia31-May-11 20:57
PozzaVecia31-May-11 20:57 
AnswerRe: abstarct class basic question Pin
RobCroll31-May-11 21:19
RobCroll31-May-11 21:19 
GeneralRe: abstarct class basic question Pin
PozzaVecia31-May-11 21:33
PozzaVecia31-May-11 21:33 
GeneralRe: abstarct class basic question Pin
BobJanova31-May-11 23:03
BobJanova31-May-11 23:03 
GeneralRe: abstarct class basic question Pin
PozzaVecia31-May-11 23:28
PozzaVecia31-May-11 23:28 
GeneralRe: abstarct class basic question Pin
BobJanova31-May-11 23:33
BobJanova31-May-11 23:33 
GeneralRe: abstarct class basic question Pin
PozzaVecia31-May-11 23:45
PozzaVecia31-May-11 23:45 
GeneralRe: abstarct class basic question Pin
Mirko19801-Jun-11 0:24
Mirko19801-Jun-11 0:24 
GeneralRe: abstarct class basic question Pin
BobJanova1-Jun-11 1:37
BobJanova1-Jun-11 1:37 
GeneralRe: abstarct class basic question Pin
Mirko19801-Jun-11 3:24
Mirko19801-Jun-11 3:24 
GeneralRe: abstarct class basic question Pin
BobJanova1-Jun-11 1:34
BobJanova1-Jun-11 1:34 
AnswerRe: abstarct class basic question Pin
Luc Pattyn1-Jun-11 0:46
sitebuilderLuc Pattyn1-Jun-11 0:46 
GeneralRe: abstarct class basic question Pin
PIEBALDconsult1-Jun-11 2:57
mvePIEBALDconsult1-Jun-11 2:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.