Click here to Skip to main content
15,920,629 members
Home / Discussions / Windows Forms
   

Windows Forms

 
AnswerRe: T9 predictive text in Windows Forms Pin
Peace ON29-Jun-10 21:02
Peace ON29-Jun-10 21:02 
GeneralRe: T9 predictive text in Windows Forms Pin
G-Tek30-Jun-10 0:57
G-Tek30-Jun-10 0:57 
GeneralRe: T9 predictive text in Windows Forms Pin
darkelv30-Jun-10 2:30
darkelv30-Jun-10 2:30 
AnswerRe: T9 predictive text in Windows Forms Pin
Eddy Vluggen4-Jul-10 1:44
professionalEddy Vluggen4-Jul-10 1:44 
QuestionSetting the size of the Windows Media Player DRM license window Pin
tjeffries23-Jun-10 16:19
tjeffries23-Jun-10 16:19 
AnswerRe: Setting the size of the Windows Media Player DRM license window Pin
Eddy Vluggen26-Jun-10 1:28
professionalEddy Vluggen26-Jun-10 1:28 
QuestionCustom control help! Pin
venomation18-Jun-10 6:33
venomation18-Jun-10 6:33 
AnswerRe: Custom control help! Pin
Luc Pattyn18-Jun-10 7:41
sitebuilderLuc Pattyn18-Jun-10 7:41 
Hi again,

the problem with AutoScroll is Windows, while scrolling, will copy and move that part of the painting that it can reuse, and order your Paint handler to only paint the new stuff, the part that becomes visible by scrolling. And that interferes with your intentions.

Furthermore, your code is much too complex; you are using an image, there is no need for, nor advantage in, doing that. Here is a simple example that works well; I use a specialized panel to get double-buffering, and I invalidate the (entire) panel when scrolling, forcing an all-paint, no-copy approach.

Panel p;
int nHor=40;
int nVert=10;
int wid=20;
int hei=20;
public void Demo() {
    Form f=new Form();
    f.Bounds=new Rectangle(0, 0, 500, 500);
    p=new UserDrawnPanel();
    // or p=new Panel();
    p.Bounds=new Rectangle(20, 20, 400, 400);
    p.AutoScroll=true;
    p.AutoScrollMinSize=new Size(nHor*wid+10, nVert*hei+10);
    p.BackColor=Color.White;
    p.Paint+=new PaintEventHandler(p_Paint);
    p.Scroll+=new ScrollEventHandler(p_Scroll);
    f.Controls.Add(p);
    f.Show();
}

void p_Scroll(object sender, ScrollEventArgs e) {
    log("Scroll="+e.NewValue);
    p.Invalidate();
}

void p_Paint(object sender, PaintEventArgs e) {
    Graphics g=e.Graphics;
    log("ClipRectangle="+e.ClipRectangle);
    log("AutoScrollPosition="+p.AutoScrollPosition);
    g.TranslateTransform(p.AutoScrollPosition.X, p.AutoScrollPosition.Y);
    for (int y=0; y<=nVert; y++) g.DrawLine(Pens.Black, 0, y*hei, nHor*wid, y*hei);
    for (int x=0; x<=nHor ; x++) g.DrawLine(Pens.Black, x*wid, 0, x*wid, nVert*hei);
}

class UserDrawnPanel : Panel {
    public UserDrawnPanel() {
        SetStyle(ControlStyles.UserPaint, true);
        SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    }
}


BTW: you can safely ignore the log statements.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.


GeneralRe: Custom control help! Pin
venomation18-Jun-10 8:10
venomation18-Jun-10 8:10 
GeneralRe: Custom control help! Pin
Luc Pattyn18-Jun-10 8:11
sitebuilderLuc Pattyn18-Jun-10 8:11 
QuestionHow to create xmpp client using C#? Pin
manjeeet17-Jun-10 23:05
manjeeet17-Jun-10 23:05 
Answercross-post Pin
Luc Pattyn18-Jun-10 2:29
sitebuilderLuc Pattyn18-Jun-10 2:29 
AnswerRe: How to create xmpp client using C#? Pin
LloydA11120-Jun-10 9:24
LloydA11120-Jun-10 9:24 
QuestionWindow resizing Pin
Lamazhab17-Jun-10 5:37
Lamazhab17-Jun-10 5:37 
AnswerRe: Window resizing Pin
Luc Pattyn17-Jun-10 6:41
sitebuilderLuc Pattyn17-Jun-10 6:41 
GeneralRe: Window resizing Pin
Lamazhab24-Jun-10 12:59
Lamazhab24-Jun-10 12:59 
AnswerRe: Window resizing Pin
Lamazhab17-Jun-10 8:21
Lamazhab17-Jun-10 8:21 
GeneralRe: Window resizing Pin
Luc Pattyn17-Jun-10 8:49
sitebuilderLuc Pattyn17-Jun-10 8:49 
GeneralRe: Window resizing Pin
Lamazhab24-Jun-10 13:02
Lamazhab24-Jun-10 13:02 
GeneralRe: Window resizing Pin
Luc Pattyn24-Jun-10 13:08
sitebuilderLuc Pattyn24-Jun-10 13:08 
QuestionAutomatically add a new row when the user presses "Tab" Pin
sri_009915-Jun-10 23:40
sri_009915-Jun-10 23:40 
AnswerRe: Automatically add a new row when the user presses "Tab" Pin
Som Shekhar16-Jun-10 2:05
Som Shekhar16-Jun-10 2:05 
QuestionUSB drive reader Pin
S.Aijaz14-Jun-10 3:45
S.Aijaz14-Jun-10 3:45 
Answercross-post Pin
Luc Pattyn14-Jun-10 3:55
sitebuilderLuc Pattyn14-Jun-10 3:55 
QuestionCustom controll flickers! Pin
venomation9-Jun-10 9:28
venomation9-Jun-10 9:28 

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.