Click here to Skip to main content
15,895,829 members
Home / Discussions / C#
   

C#

 
AnswerRe: Image Processing Pin
Luc Pattyn28-Jun-07 11:28
sitebuilderLuc Pattyn28-Jun-07 11:28 
GeneralRe: Image Processing Pin
james_dixon_200828-Jun-07 11:44
james_dixon_200828-Jun-07 11:44 
GeneralRe: Image Processing Pin
Christian Graus28-Jun-07 11:47
protectorChristian Graus28-Jun-07 11:47 
GeneralRe: Image Processing Pin
james_dixon_200828-Jun-07 12:08
james_dixon_200828-Jun-07 12:08 
GeneralRe: Image Processing Pin
Luc Pattyn28-Jun-07 12:33
sitebuilderLuc Pattyn28-Jun-07 12:33 
AnswerRe: Image Processing Pin
Amar Chaudhary28-Jun-07 12:30
Amar Chaudhary28-Jun-07 12:30 
AnswerRe: Image Processing Pin
gumi_r@msn.com29-Jun-07 4:37
gumi_r@msn.com29-Jun-07 4:37 
QuestionScrollProperties.Value needs to be set twice? Pin
PhilDanger28-Jun-07 11:12
PhilDanger28-Jun-07 11:12 
Hey all,

I've got some C# code that zooms in on an image contained in a Panel, and moves that panel's scroll bars to center on the place that was clicked on with the zoom tool. However, when I set the Value property of the ScrollProperties as shown below, the value stays the same unless I execute the same code twice in a row, as shown below. If I do it only once, it will center correctly, but the actual scroll bars will not move until the next set of the .Value property. Any ideas why?


/// <summary>
/// Positions the vertial and horizontal scroll bars by the given X and Y offsets
/// </summary>
private void CenterScrollBars(int X, int Y)
{
    //horizontal scroll bar first
    HScrollProperties hsp = MainPanel.HorizontalScroll;
    if (hsp.Visible) //if we don't have a scroll bar, don't try moving it!
    {
        //calculate the offset to move the scroll bar in order to center on the clicked point
        //since the point uses the DrawingBox's coordinate system, we need to move it into the
        //containing panel's coordinate system first by doing a shift
        int offs = (X + DrawBox.Location.X) - (MainPanel.Width / 2);
        MoveScrollPosition(hsp, offs);
    }
    //vertical next
    VScrollProperties vsp = MainPanel.VerticalScroll;
    if (vsp.Visible)  //if we don't have a scroll bar, don't try moving it!
    {
        //same idea as above
        int offs = (Y + DrawBox.Location.Y) - (MainPanel.Height / 2);
        MoveScrollPosition(vsp, offs);
    }



}

/// <summary>
/// Moves the scroll bar by the specified offset, clamping to min or maximum if needed
/// </summary>
/// <param name="sp">The scroll bar to move</param>
/// <param name="offset">The offset by which to move the scroll bar.</param>
private void MoveScrollPosition(ScrollProperties sp, int offset)
{
    int val = sp.Value + offset;
    //clamp the value to the min and max values of the scroll bar
    if (val < sp.Minimum)
    {
        val = sp.Minimum;
    }
    else if (val > sp.Maximum)
    {
        val = sp.Maximum;
    }
    sp.Value = val;
    sp.Value = val; //TODO -- investigate this problem, scroll bar position not updated properly unless this is done twice
}


Thanks!
AnswerRe: ScrollProperties.Value needs to be set twice? Pin
Luc Pattyn28-Jun-07 11:35
sitebuilderLuc Pattyn28-Jun-07 11:35 
AnswerRe: ScrollProperties.Value needs to be set twice? Pin
Mark Greenwood28-Jun-07 11:36
Mark Greenwood28-Jun-07 11:36 
AnswerRe: ScrollProperties.Value needs to be set twice? Pin
PhilDanger29-Jun-07 10:16
PhilDanger29-Jun-07 10:16 
AnswerRe: ScrollProperties.Value needs to be set twice? Pin
yurets__5-Jul-10 3:39
yurets__5-Jul-10 3:39 
QuestionSQL 2005 Connection Problem Pin
Muhammad Nauman Yousuf28-Jun-07 9:29
Muhammad Nauman Yousuf28-Jun-07 9:29 
AnswerRe: SQL 2005 Connection Problem Pin
Muhammad Qasim Pasta28-Jun-07 9:38
Muhammad Qasim Pasta28-Jun-07 9:38 
AnswerRe: SQL 2005 Connection Problem Pin
originSH28-Jun-07 22:06
originSH28-Jun-07 22:06 
QuestionXMLSerializer formatting xsi:xxx="whatever" in my namespace declaration. Pin
glenn8828-Jun-07 8:55
glenn8828-Jun-07 8:55 
AnswerRe: XMLSerializer formatting xsi:xxx="whatever" in my namespace declaration. Pin
BoneSoft28-Jun-07 12:04
BoneSoft28-Jun-07 12:04 
GeneralRe: XMLSerializer formatting xsi:xxx="whatever" in my namespace declaration. Pin
whenrybruce30-Mar-09 7:32
whenrybruce30-Mar-09 7:32 
QuestionForm Resizing Problems Pin
PhilDanger28-Jun-07 8:55
PhilDanger28-Jun-07 8:55 
AnswerRe: Form Resizing Problems Pin
Dave Kreskowiak28-Jun-07 9:30
mveDave Kreskowiak28-Jun-07 9:30 
GeneralRe: Form Resizing Problems Pin
PhilDanger28-Jun-07 9:42
PhilDanger28-Jun-07 9:42 
AnswerRe: Form Resizing Problems Pin
Luc Pattyn28-Jun-07 10:12
sitebuilderLuc Pattyn28-Jun-07 10:12 
GeneralRe: Form Resizing Problems Pin
PhilDanger28-Jun-07 10:58
PhilDanger28-Jun-07 10:58 
GeneralRe: Form Resizing Problems Pin
Luc Pattyn28-Jun-07 11:19
sitebuilderLuc Pattyn28-Jun-07 11:19 
Questionexecute Pin
SVb.net28-Jun-07 8:09
SVb.net28-Jun-07 8:09 

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.