Click here to Skip to main content
16,020,289 members
Home / Discussions / C#
   

C#

 
AnswerRe: Trying to print an html page without to load it in asp.net Pin
Not Active13-Jul-06 5:24
mentorNot Active13-Jul-06 5:24 
AnswerRe: Trying to print an html page without to load it in asp.net Pin
Dave Kreskowiak13-Jul-06 6:38
mveDave Kreskowiak13-Jul-06 6:38 
GeneralRe: Trying to print an html page without to load it in asp.net Pin
sai_akkina13-Jul-06 18:11
sai_akkina13-Jul-06 18:11 
Questionmoving an image Pin
john3413-Jul-06 5:00
john3413-Jul-06 5:00 
AnswerRe: moving an image Pin
Christian Graus13-Jul-06 5:09
protectorChristian Graus13-Jul-06 5:09 
AnswerRe: moving an image Pin
Robert Rohde13-Jul-06 5:17
Robert Rohde13-Jul-06 5:17 
AnswerRe: moving an image Pin
Dave Kreskowiak13-Jul-06 6:51
mveDave Kreskowiak13-Jul-06 6:51 
AnswerRe: moving an image [modified] Pin
Dave Kreskowiak13-Jul-06 10:19
mveDave Kreskowiak13-Jul-06 10:19 
Whipped this up in about 20 minutes. (I couldn't wrap my brain around the stinking math for a little while!)

Create a new UserControl, call it ScrollablePicture or whatever. Drop a Panel on the design surface and set its Dock property to Fill, then it's AutoScroll property to True. Drop a PictureBox control on the Panel. You don't have to change any of it's properties.

Then:
public class ScrollablePicture {
    
    private Point m_CursorOffset;
    private int m_CurrentHScroll;
    private int m_CurrentVScroll;
    private bool m_Scrolling = false;
    
    public ScrollablePicture() {
        //  This call is required by the Windows Form Designer.
        InitializeComponent();
        //  Add any initialization after the InitializeComponent() call.
        this.Cursor = Cursors.Hand;
    }
    
    public Image Image {
        get {
            return PictureBox1.Image;
        }
        set {
            if (value != null) {
                PictureBox1.Size = value.Size;
                PictureBox1.Image = value;
            }
        }
    }
    
    private void PictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
        if ((e.Button == Windows.Forms.MouseButtons.Left)) {
            m_CursorOffset = Panel1.PointToClient(System.Windows.Forms.Cursor.Position);
            m_CurrentHScroll = Panel1.HorizontalScroll.Value;
            m_CurrentVScroll = Panel1.VerticalScroll.Value;
            m_Scrolling = true;
        }
    }
    
    private void PictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
        if (m_Scrolling) {
            Point Offset = Panel1.PointToClient(System.Windows.Forms.Cursor.Position);
            int newH = (m_CurrentHScroll 
                        + (m_CursorOffset.X - Offset.X));
            int newV = (m_CurrentVScroll 
                        + (m_CursorOffset.Y - Offset.Y));

            // I hate generating tons of ArgumentOutOfRange exceptions for no
            // good reason, so we'll just make sure that the new scroll values are good.
            if ((newH < Panel1.HorizontalScroll.Minimum)) {
                newH = Panel1.HorizontalScroll.Minimum;
            }
            else if ((newH > Panel1.HorizontalScroll.Maximum)) {
                newH = Panel1.HorizontalScroll.Maximum;
            }
            if ((newV < Panel1.VerticalScroll.Minimum)) {
                newV = Panel1.VerticalScroll.Minimum;
            }
            else if ((newV > Panel1.VerticalScroll.Maximum)) {
                newV = Panel1.VerticalScroll.Maximum;
            }
            Panel1.HorizontalScroll.Value = newH;
            Panel1.VerticalScroll.Value = newV;
        }
    }
    
    private void PictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
        m_Scrolling = false;
    }
}

* Code coverted from VB.NET to C# by CarlosAg.net[^]


Dave Kreskowiak
Microsoft MVP - Visual Basic



-- modified at 16:21 Thursday 13th July, 2006
GeneralRe: moving an image Pin
john3413-Jul-06 23:03
john3413-Jul-06 23:03 
QuestionPassing more than one QueryString Pin
leckey13-Jul-06 4:28
leckey13-Jul-06 4:28 
AnswerRe: Passing more than one QueryString Pin
Not Active13-Jul-06 4:55
mentorNot Active13-Jul-06 4:55 
QuestionDoing own ToolStripItems… Pin
anderslundsgard13-Jul-06 4:26
anderslundsgard13-Jul-06 4:26 
AnswerRe: Doing own ToolStripItems… Pin
Ed.Poore15-Jul-06 13:04
Ed.Poore15-Jul-06 13:04 
QuestionConverting a Color to RGB (not ARGB) Pin
anderslundsgard13-Jul-06 3:27
anderslundsgard13-Jul-06 3:27 
AnswerRe: Converting a Color to RGB (not ARGB) Pin
stancrm13-Jul-06 3:34
stancrm13-Jul-06 3:34 
GeneralRe: Converting a Color to RGB (not ARGB) Pin
anderslundsgard13-Jul-06 4:06
anderslundsgard13-Jul-06 4:06 
GeneralRe: Converting a Color to RGB (not ARGB) Pin
Christian Graus13-Jul-06 4:22
protectorChristian Graus13-Jul-06 4:22 
GeneralRe: Converting a Color to RGB (not ARGB) Pin
stancrm13-Jul-06 8:40
stancrm13-Jul-06 8:40 
QuestionRun store procedure in C# setup Pin
Saamir13-Jul-06 3:22
Saamir13-Jul-06 3:22 
AnswerRe: Run store procedure in C# setup Pin
Christian Graus13-Jul-06 4:23
protectorChristian Graus13-Jul-06 4:23 
GeneralRe: Run store procedure in C# setup Pin
BoneSoft13-Jul-06 6:21
BoneSoft13-Jul-06 6:21 
GeneralRe: Run store procedure in C# setup Pin
Saamir16-Jul-06 8:25
Saamir16-Jul-06 8:25 
Questionproblem with starting windows forms ? help plz... Pin
cmpeng3413-Jul-06 2:59
cmpeng3413-Jul-06 2:59 
AnswerRe: problem with starting windows forms ? help plz... Pin
stancrm13-Jul-06 3:07
stancrm13-Jul-06 3:07 
AnswerRe: problem with starting windows forms ? help plz... Pin
Ravi Bhavnani13-Jul-06 4:50
professionalRavi Bhavnani13-Jul-06 4:50 

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.