Click here to Skip to main content
15,894,460 members
Home / Discussions / C#
   

C#

 
QuestionMoving Controls only inside the panel Pin
Spessotto11-Oct-13 2:45
Spessotto11-Oct-13 2:45 
AnswerRe: Moving Controls only inside the panel Pin
BillWoodruff12-Oct-13 14:21
professionalBillWoodruff12-Oct-13 14:21 
You need to set the Cursor's Clip Rectangle in the MouseDown EventHandler for the TextBox to that of its container's ClientRectangle translated to Screen coordinates, using an offset based on the Height and Width of the TextBox:
C#
// Add to your MouseDown EventHandler

Cursor.Clip = YourTextBox.Parent.RectangleToScreen
(
    new Rectangle
    (
        e.X,
        e.Y,
        YourTextBox.Parent.ClientSize.Width - YourTextBox.Width,
        YourTextBox.Parent.ClientSize.Height - YourTextBox.Height
    )
);
And, in the MouseUp EventHandler for the TextBox:
// Add to your MouseUp EventHandler

Cursor.Clip = Rectangle.Empty;
If the Control that contains the TextBox is never resized at run-time, then, of course, you can store its ClientRectangle translated to Screen coordinates in advance. If the TextBox is always the same size, you can pre-calculate the offset Rectangle only once, and then, in the MouseDown EventHandler, just set the Location depending on the MouseDown's MouseEventArgs.Location.

This may not seem intuitive Smile | :) .

Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview


modified 13-Oct-13 1:51am.

GeneralRe: Moving Controls only inside the panel Pin
Spessotto14-Oct-13 1:18
Spessotto14-Oct-13 1:18 
QuestionGridView Pin
Member 1032928610-Oct-13 23:45
Member 1032928610-Oct-13 23:45 
AnswerRe: GridView Pin
harold aptroot11-Oct-13 1:03
harold aptroot11-Oct-13 1:03 
GeneralRe: GridView Pin
Member 1032928611-Oct-13 22:50
Member 1032928611-Oct-13 22:50 
GeneralRe: GridView Pin
harold aptroot11-Oct-13 23:04
harold aptroot11-Oct-13 23:04 
QuestionHow to use PrintQueue.AddJob()? Pin
aygrhnwms30410-Oct-13 16:05
aygrhnwms30410-Oct-13 16:05 
QuestionRe: How to use PrintQueue.AddJob()? Pin
Richard MacCutchan10-Oct-13 20:58
mveRichard MacCutchan10-Oct-13 20:58 
QuestionBest way to store MASSIVE amounts of data? Pin
SledgeHammer0110-Oct-13 15:37
SledgeHammer0110-Oct-13 15:37 
AnswerRe: Best way to store MASSIVE amounts of data? Pin
Richard Andrew x6410-Oct-13 16:31
professionalRichard Andrew x6410-Oct-13 16:31 
GeneralRe: Best way to store MASSIVE amounts of data? Pin
SledgeHammer0110-Oct-13 17:04
SledgeHammer0110-Oct-13 17:04 
AnswerRe: Best way to store MASSIVE amounts of data? Pin
Mycroft Holmes10-Oct-13 16:43
professionalMycroft Holmes10-Oct-13 16:43 
GeneralRe: Best way to store MASSIVE amounts of data? Pin
SledgeHammer0110-Oct-13 17:04
SledgeHammer0110-Oct-13 17:04 
GeneralRe: Best way to store MASSIVE amounts of data? Pin
Mycroft Holmes10-Oct-13 17:28
professionalMycroft Holmes10-Oct-13 17:28 
AnswerRe: Best way to store MASSIVE amounts of data? Pin
Garth J Lancaster10-Oct-13 17:09
professionalGarth J Lancaster10-Oct-13 17:09 
AnswerRe: Best way to store MASSIVE amounts of data? Pin
s_magus10-Oct-13 18:53
s_magus10-Oct-13 18:53 
AnswerRe: Best way to store MASSIVE amounts of data? Pin
jschell11-Oct-13 9:28
jschell11-Oct-13 9:28 
AnswerRe: Best way to store MASSIVE amounts of data? Pin
Ennis Ray Lynch, Jr.11-Oct-13 9:45
Ennis Ray Lynch, Jr.11-Oct-13 9:45 
QuestionC# Code generation .net 4.5 Pin
no_time10-Oct-13 9:08
no_time10-Oct-13 9:08 
AnswerRe: C# Code generation .net 4.5 Pin
Richard Andrew x6410-Oct-13 9:50
professionalRichard Andrew x6410-Oct-13 9:50 
AnswerRe: C# Code generation .net 4.5 Pin
Homero Rivera10-Oct-13 12:53
Homero Rivera10-Oct-13 12:53 
AnswerRe: C# Code generation .net 4.5 Pin
Keld Ølykke10-Oct-13 22:04
Keld Ølykke10-Oct-13 22:04 
Questionhow to restrict a method call only once Pin
srinimuk9-Oct-13 22:32
srinimuk9-Oct-13 22:32 
QuestionRe: how to restrict a method call only once Pin
Richard MacCutchan9-Oct-13 22:53
mveRichard MacCutchan9-Oct-13 22:53 

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.