Click here to Skip to main content
15,908,901 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can I run exe file? Pin
KennyPatel18-Nov-07 19:04
KennyPatel18-Nov-07 19:04 
QuestionControl Button Access Pin
zafax_17-Nov-07 22:23
zafax_17-Nov-07 22:23 
AnswerRe: Control Button Access Pin
pmarfleet17-Nov-07 22:58
pmarfleet17-Nov-07 22:58 
Questiondatatable name is not set Pin
caradri17-Nov-07 21:50
caradri17-Nov-07 21:50 
AnswerRe: datatable name is not set Pin
pmarfleet17-Nov-07 22:53
pmarfleet17-Nov-07 22:53 
AnswerRe: datatable name is not set Pin
itiwant3-Dec-10 7:10
itiwant3-Dec-10 7:10 
Questionhow to switch between languages in windows? Pin
Shaahinm17-Nov-07 21:46
Shaahinm17-Nov-07 21:46 
Question(WPF)Porting Pan functionality from WinForms [modified] Pin
wolfshad317-Nov-07 19:46
wolfshad317-Nov-07 19:46 
solved mostly: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2423864&SiteID=1&mode=1

I have this functionality i want to port from WinForms but i run into a few problems and i can't continue. What it does is move a panel(canvas) around as i click and hold and drag the mouse). I saw the sample using TranlateTransform(XAML) but i can't get any code-behind example, this is dynamic and interactive. I managed to make some out only need the translation solved(and possibly a good approach on using this with Margin, wich seems the only tool i got to moving the canvas around?).

Code Block#region Pan tool
private bool mMovingPanel;
private Point mMousePos;
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
mMovingPanel = e.Button == MouseButtons.Left;
// prev mouse pos
mMousePos = panel1.PointToScreen(e.Location);
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (mMovingPanel)
{
// "this mouse pos"
Point pos = panel1.PointToScreen(e.Location);
// "this mouse pos" - "prev mouse pos" = offset
Size adj = new Size(pos.X - mMousePos.X, pos.Y - mMousePos.Y);
// Location + offset = Location (final - unassigned)
Point loc = panel1.Location + adj;
if (panel1.Width >= this.ClientSize.Width && panel1.Height >= this.ClientSize.Height)
{
if (loc.X > 0) loc.X = 0;
if (loc.X + panel1.Width < this.ClientSize.Width) loc.X = this.ClientSize.Width - panel1.Width;
if (loc.Y > 0) loc.Y = 0;
if (loc.Y + panel1.Height < this.ClientSize.Height) loc.Y = this.ClientSize.Height - panel1.Height;
}
else if (panel1.Height >= this.ClientSize.Height)
{
if (loc.X < 0) loc.X = 0;
if (loc.X + panel1.Width > this.ClientSize.Width) loc.X = this.ClientSize.Width - panel1.Width;
if (loc.Y > 0) loc.Y = 0;
if (loc.Y + panel1.Height < this.ClientSize.Height) loc.Y = this.ClientSize.Height - panel1.Height;
}
else
{
if (loc.X < 0) loc.X = 0;
if (loc.X + panel1.Width > this.ClientSize.Width) loc.X = this.ClientSize.Width - panel1.Width;
if (loc.Y < 0) loc.Y = 0;
if (loc.Y + panel1.Height > this.ClientSize.Height) loc.Y = this.ClientSize.Height - panel1.Height;
}
// Location(final - assigned)
panel1.Location = loc;
// "this mouse pos" set aside as "prev mouse pos"
mMousePos = pos;
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
mMovingPanel = false;
}
#endregion





This is my attempt, i know it lacks but hopefully it will speed things up:




Code Block#region Pan tool
private bool mMovingPanel;
private Point mMousePos;
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
mMovingPanel = Mouse.LeftButton == MouseButtonState.Pressed;
// prev mouse pos
mMousePos = canvas1.PointToScreen(Mouse.GetPosition(canvas1));

}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (mMovingPanel)
{
// "this mouse pos"
Point pos = canvas1.PointToScreen(Mouse.GetPosition(canvas1));
// "this mouse pos" - "prev mouse pos" = offset
Vector adj = new Vector(pos.X - mMousePos.X, pos.Y - mMousePos.Y);
// Location + offset = Location (final - unassigned)
Thickness currentThickness = new Thickness();
Thickness loc = new Thickness(currentThickness.Left + adj.X, currentThickness.Top + adj.Y,
currentThickness.Right, currentThickness.Bottom);
if (canvas1.ActualWidth >= this.ActualWidth && canvas1.ActualHeight >= this.ActualHeight)
{
if (loc.Left > 0) loc.Left = 0;
if (loc.Left + canvas1.ActualWidth < this.ActualWidth) loc.Left = this.ActualWidth - canvas1.ActualWidth;
if (loc.Top > 0) loc.Top = 0;
if (loc.Top + canvas1.ActualHeight < this.ActualHeight) loc.Top = this.ActualHeight - canvas1.ActualHeight;
}
else if (canvas1.ActualHeight >= this.ActualHeight)
{
if (loc.Left < 0) loc.Left = 0;
if (loc.Left + canvas1.ActualWidth > this.ActualWidth) loc.Left = this.ActualWidth - canvas1.ActualWidth;
if (loc.Top > 0) loc.Top = 0;
if (loc.Top + canvas1.ActualHeight < this.ActualHeight) loc.Top = this.ActualHeight - canvas1.ActualHeight;
}
else
{
if (loc.Left < 0) loc.Left = 0;
if (loc.Left + canvas1.ActualWidth > this.ActualWidth) loc.Left = this.ActualWidth - canvas1.ActualWidth;
if (loc.Top < 0) loc.Top = 0;
if (loc.Top + canvas1.ActualHeight > this.ActualHeight) loc.Top = this.ActualHeight - canvas1.ActualHeight;
}
// Location(final - assigned)
canvas1.Margin = loc;
// "this mouse pos" set aside as "prev mouse pos"
mMousePos = pos;
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
mMovingPanel = false;
}
#endregion



-- modified at 1:04 Monday 19th November, 2007
QuestionSource code protection Pin
triag17-Nov-07 18:32
triag17-Nov-07 18:32 
AnswerRe: Source code protection Pin
Michael Sync17-Nov-07 18:51
Michael Sync17-Nov-07 18:51 
GeneralRe: Source code protection Pin
triag17-Nov-07 20:03
triag17-Nov-07 20:03 
GeneralRe: Source code protection Pin
Michael Sync17-Nov-07 21:03
Michael Sync17-Nov-07 21:03 
GeneralRe: Source code protection Pin
triag17-Nov-07 21:23
triag17-Nov-07 21:23 
GeneralRe: Source code protection Pin
pmarfleet17-Nov-07 22:45
pmarfleet17-Nov-07 22:45 
AnswerRe: Source code protection Pin
Michael Davey 117-Nov-07 19:05
Michael Davey 117-Nov-07 19:05 
Questiondata grid view in c# Pin
w20917-Nov-07 17:27
w20917-Nov-07 17:27 
AnswerRe: data grid view in c# Pin
Michael Sync17-Nov-07 18:49
Michael Sync17-Nov-07 18:49 
QuestionLanguage of Resource DLL (.net) Pin
M i s t e r L i s t e r17-Nov-07 13:42
M i s t e r L i s t e r17-Nov-07 13:42 
AnswerRe: Language of Resource DLL (.net) Pin
wizfrog17-Nov-07 14:10
wizfrog17-Nov-07 14:10 
GeneralRe: Language of Resource DLL (.net) Pin
M i s t e r L i s t e r18-Nov-07 6:57
M i s t e r L i s t e r18-Nov-07 6:57 
QuestionUsing an XML DB in Visual C# Pin
wizfrog17-Nov-07 13:38
wizfrog17-Nov-07 13:38 
AnswerRe: Using an XML DB in Visual C# Pin
Not Active17-Nov-07 14:11
mentorNot Active17-Nov-07 14:11 
GeneralRe: Using an XML DB in Visual C# Pin
wizfrog17-Nov-07 14:35
wizfrog17-Nov-07 14:35 
GeneralRe: Using an XML DB in Visual C# Pin
Not Active17-Nov-07 16:37
mentorNot Active17-Nov-07 16:37 
QuestionNode List Problem Pin
merrsh197817-Nov-07 11:23
merrsh197817-Nov-07 11:23 

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.