|
Hi
i have this code to create a new control (inherites from Panel) and when user over it, click mouse and drag, a new rectangle create and resize to fit with mouse position cordination:
public partial class Stage : Panel
{
int originX = 0;
int originY = 0;
bool dragging = false;
public Stage()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
}
protected override void OnMouseDown(MouseEventArgs e)
{
this.dragging = true;
this.originX = e.X;
this.originY = e.Y;
Graphics g = this.CreateGraphics();
g.DrawRectangle(new Pen(Brushes.Red, 4), this.originX, this.originY, this.originX, this.originY);
this.Invalidate();
base.OnMouseDown(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (this.dragging)
{
int posX = e.X;
int posY = e.Y;
Graphics g = this.CreateGraphics();
g.DrawRectangle(new Pen(Brushes.Red, 4), this.originX, this.originY, posX, posY);
this.Invalidate();
}
base.OnMouseMove(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (this.dragging)
this.dragging = false;
base.OnMouseUp(e);
}
}
but at runTime, it work so bad with flicker and when mouse button released. not any rectangle exist in Stage control.
can anyBody help me to find out how to create rectangle whith drag and drop correctly ?
thanks
|
|
|
|
|
use BufferedGraphics object
see this link[^]
or
link[^]
hope it helps
dhaim
programming is a hobby that make some money as side effect
|
|
|
|
|
Ok, first - don't draw using CreateGraphics. Override the OnPaint method, or register for the OnPaint Event.
Second, you can set double buffering on your form, which should reduce filcker (There should be a property on your form for this)
And the reason there is no rectangle when you've finished.. well, its because your no longer drawing any rectangle.
Rectangle rect = new Rectangle(0,0,0,0);
OnMouseDown(...)
{
this.dragging = true;
rect.X = e.X;
rect.Y = e.Y;
}
OnMouseUp(...)
{
this.dragging = false;
}
OnMouseMove(...)
{
if(this.dragging)
{
int width = e.X - this.rect.X;
int height = e.Y - this.rect.Y;
rect.Width = width;
rect.Height = height;
this.Invalidate();
}
}
OnPaint(...)
{
e.Graphics.DrawRectangle(myPen, rect);
}
Or something like that. You have to store the rectangle your creating, so that it can be drawn later on. It won't just stay there.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Hey guys.
How can we write
if (str.Length > 250) str = str.Substring(0, 250);
with ? operator ?
Thank you.
|
|
|
|
|
The ? operator is like an if-else statement with the syntax:
Condition ? Statement1 : Statement2.
Where Statement1 is the code executed if the condition is true, and Statement2 is the code executed if the condition is false.
So in your situation, something like:
str = str.Length > 250 ? str.Substring(0,250) : str;
should do it.
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
modified on Sunday, September 14, 2008 9:47 AM
|
|
|
|
|
Or
str = str.Substring(0, Math.Min(str.Length, 250));
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Perspx wrote: str = str.Length > 250 ? str.Substring(0,250) : str.Substring(0,str.Length);
The expression str.Substring(0,str.Length) is rather pointless, as it returns a string identical to str.
Just do:
str = str.Length > 250 ? str.Substring(0,250) : str;
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yes, sorry, I noticed that after I posted.
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
|
|
|
|
|
Hello ,
i'm using the office 2007 ribbon.. so i deleted the control bar by setting the Form Border Style to None.
So i can't drag-n-drop all the window now ...
i don't kno how can i tell the control to delegate the drag-n-drop event to the parent container ... ( the window )
i hope that my question is clear .. thank you.
ps : sorry for my bad english
modified on Sunday, September 14, 2008 7:36 AM
|
|
|
|
|
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;
[DllImport("User32.dll")]
public static extern bool ReleaseCapture();
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}
I founder it from Syncfusion. ([^])
Chuck Norris has the greatest Poker-Face of all time. He won the 1983 World Series of Poker, despite holding only a Joker, a Get out of Jail Free Monopoloy card, a 2 of clubs, 7 of spades and a green #4 card from the game UNO. In the movie "The Matrix", Chuck Norris is the Matrix. If you pay close attention in the green "falling code" scenes, you can make out the faint texture of his beard. Chuck Norris actually owns IBM. It was an extremely hostile takeover.
|
|
|
|
|
Hi All,
I'm just setting up a new solution for a refactoring exercise. I have a few projects in the solution that all have post-build events to copy them to location where I'm compositing the application files.
How do I set-up Visual Studio to debug c:\app\app.exe when I hit F5 instead of it simply starting the .exe in the bin\debug directory?
Cheers,
|
|
|
|
|
Under the project's properties go to the Debug options, select "Start External Program" and put the path to your app in the text field.
|
|
|
|
|
I'm at a loss. Hoping someone can help.
I'm creating a custom control which inherits from Control (not sure if that's where I went wrong to start with) but here's the problem.
Based on a property which holds an array of strings, a certain number of panels are added to the control.
When the setter function of the string array property is called, the panels are added as follows:
this.Controls.Clear();
foreach (string s in myStrings)
{
Panel newPanel = new Panel();
newPanel.Name = ...;
newPanel.Location = ...;
newPanel.Size = ...;
newPanel.Paint += new System.Windows.Forms.PaintEventHandler(panelTab_Paint);
this.Controls.Add(newPanel);
}
And the paint function callback looks something like this:
private void panelTab_Paint(object sender, PaintEventArgs e)
{
}
So the problem is that, inside the function above, the value for e.ClipRectangle is {X = 0 Y = 0 Width = 0 Height = 0} which is obviously not right. The size of the Panel which can be obtained through sender is a valid size but why is the ClipRectangle of the PaintEventArgs value zero?
|
|
|
|
|
I'm not sure, but you could also check e.Graphics.Clip , e.Graphics.ClipBounds and e.Graphics.VisisbleClibBounds . You probably want to try ClipBounds though.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
The thing is, I'm not so much interested in obtaining those values, I mean I can quite easily do that by using (sender as Panel).Size and (sender as Panel).Location . I do want to be able to paint on the panel with e.Graphics.DrawLine(...) and such but as long as the e.ClipRectangle value is zero, nothing I draw on the panel will be successful as it falls outside of the clipping rectangle.
|
|
|
|
|
Oh bother! It seems my problem is bigger than just that. But at least, I suspect that if I can sort this one out it will be a sollution to the above as well.
I've now tried to implement an OnClick event for the Panels by adding this:
newPanel.Click += new EventHandler(panelTab_Click);
just before this:
this.Controls.Add(newPanel);
and defining panelTab_Click as follows:
private void panelTab_Click(object sender, EventArgs e)
{
}
However, even though the tabs are being added to the control they wouldn't respond to mouse clicks and the function above is never called. I'm reasonably sure that I'm adding the event handler correctly so I think my problem is with the way I'm adding these panels to the control in the first place. Any ideas?
modified on Sunday, September 14, 2008 1:42 PM
|
|
|
|
|
hi every body
i want know how can i send data to database without repetition
example:
string s="jack";
string x ="Axe";
String v ="jack";
string z ="tom";
string a="Axe";
with normal way "jack"&"Axe" will send twice to the database
i want send it one time only
how can i do this ??
|
|
|
|
|
Please stop using the bold font for your postings, it's annoying.
You could put all your strings into a hashtable, this will ignore duplicates:
Dictionary<string, string> strings = new Dictionary<string, string>();
strings[s] = s;
strings[x] = x;
strings[v] = v;
strings[z] = z;
strings[a] = a;
Then when adding them to the database simply iterate over the Values collection.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
First don't use bold on your question.
Check if string exists in database,if that string exists then don't insert otherwise do insert.
if (select count('stringvalue') from tablename where stringvaluecolumn='stringvalue')=0<br />
begin<br />
insert into tablename values('stringvalue')<br />
end<br />
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
you may want to do that in sql, database stuff you do in database ok?
ask if value exists?
NO can add to table
YES can´t add already there
(don´t know your database here)
create a procedure my_insert_procedure
@whatever varchar(50)
as
begin
if not exists(select * from my_table where whatever = @whatever)
begin
insert into my_table values (@whatever)
select 'OK: value added'
end
else
begin
select 'ERROR: that value already exists'
end
end
go
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Hey guys.
How can we find windows Temp folder in c# ?
Like this :
C:\Documents and Settings\Mds\Local Settings\Temp
Thanks in advance.
|
|
|
|
|
System.IO.Path.GetTempPath() should about do it
--
Real programmers don't comment their code. It was hard to write, it should be hard to understand.
|
|
|
|
|
|
The previous answer is correct and is what I use but (for the sake of completeness) there's also
Environment.GetEnvironmentVariable("TEMP");
or
Environment.GetEnvironmentVariable("TMP");
<edit>Didn't see Giorgi's answer till after posting as it was on the next page!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Thanks a lot DaveyM69.
But I want to know is this correct :
Environment.GetEnvironmentVariable("temp");
|
|
|
|