|
You could fire the LocationChanged event and place the form back to orginal location.
Point OriginalLocation;<br />
private void Form1_Load(object sender, System.EventArgs e) {<br />
OriginalLocation = new Point(this.Left,this.Top);<br />
}<br />
<br />
private void Form1_LocationChanged(object sender, System.EventArgs e) {<br />
this.Location = OriginalLocation;<br />
}<br />
|
|
|
|
|
i have already draw many rectangle inside a form how can i move the rectangular form one position to another after i have selected the rectangular to move.
|
|
|
|
|
You can do this by changing the Rectangle Draw points and then redraw the object.
<br />
Rectangle DrawRectangle = new Rectangle(4,4,50,50);<br />
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {<br />
e.Graphics.DrawRectangle(System.Drawing.Pens.Beige, DrawRectangle);<br />
}<br />
<br />
private void button1_Click(object sender, System.EventArgs e) {<br />
DrawRectangle = new Rectangle(20,20,50,50);<br />
panel1.Invalidate();<br />
}<br />
|
|
|
|
|
thanx for your tips.i want to ask i have a lot of rectangle in the form how can i know which rectangle i have select to move and can i remain the size of the rectangle when i move and can i see the effect of the move when i move the rectangle.thank you for help me answer the question.
|
|
|
|
|
Hello All,
I get this warning:
The keyword new is required on 'MyNamespace.MyClass.Client' because it hides inherited member 'System.Net.Sockets.TcpClient.Client'
On this piece of code:
public TcpClient Client {
get { return Client; }
set { Client = value; }
} I'm not really sure what it means though. The public TcpClient Client is where the error occurs, but this is a property and I don't want it to return a new TcpClient everytime someone gets this property. The public TcpClient Client is initialized in the constructor for the class.
public MyClass ()
{
Client = new TcpClient ();
} I don't really want to just leave the warning so any ideas on what to do would be very much appreciated.
On a separate note is there any way to make the compiler treat warnings as errors?
Many thanks in advance.
- monrobot13
|
|
|
|
|
I had a thought after I posted this message. Could the source of the problem simply be that I have a property named Client and so does the base class TcpClient ?
- monrobot13
|
|
|
|
|
You are absolutely right about your new property Client hiding the base class' Client identifier. Either change your property name, or place the new keyword in the property definition.
public new TcpClient Client{... Here[^] is some more info on the subject.
Jim Stewartα:geek Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
monrobot13 wrote:
public TcpClient Client {
get { return Client; }
set { Client = value; }
}
You are going to have another problem here.
The property Client, is calling itself for the get/set methods, so you will wind up getting a StackOverflow from all of the recursion that takes place.
If you want your new Client property to return the value from the base class, then you need to specify, base.Client otherwise you need to rename the variable Client so you don't get this infinite recursion.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks for the response James.
James T. Johnson wrote:
The property Client, is calling itself for the get/set methods, so you will wind up getting a StackOverflow from all of the recursion that takes place.
I took your adivce and renamed the property to something else, but I'm still getting a StackOverflow. Any ideas as to why?
If I step through the code it keeps executing the set method, but I have no idea why, would it be possible for you to explain.
Thanks again.
- monrobot13
|
|
|
|
|
Is CSharp similar to C like in variables, conditions, pointers, etc.
Can you tell me what is diferent that way i can learn more faster.
Thanks.
|
|
|
|
|
Here[^] is the "Getting Started" section in MSDN. It has several links to the introductory material for C#.
Jim Stewartα:geek Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
I can't find it
|
|
|
|
|
I want to build a C# app that wraps other executables. Any suggestions?
|
|
|
|
|
If you are trying to run an external process you need to look at the System.Diagnostics.Process class and use the Process.Start() method.
quorum pars magna fui
|
|
|
|
|
Thanks, Chris,
This is what I was hoping for. I want to build a service that monitors an application, detects problems, shuts it down, cleans things up, and then re-starts the application. At first I was wondering why this capability was under System.Diagnostics - but in the context of what I want to use it for, it makes perfect sense.
Sean Onion
|
|
|
|
|
Glad to help. There may be a similar app here on CP. Try searching the site using the google advanced search pointed here.
quorum pars magna fui
|
|
|
|
|
Hey i was wondering if anyone could give me a link or book name that has C#/DirectX 9.0 tutorials.
Yes, Shock I know you are doing them here but I have already done them and figured out DirectInput and was hoping for a more fast paced tutorial. I can help wiht DInput if you like.
|
|
|
|
|
I have a TextBox that is part of a control (toolbar) that is part of another
control (an Explorer band object); no forms involved. This TextBox is
defined thus:
this.searchTextBox.Location = new System.Drawing.Point(48, 24);
this.searchTextBox.Name = "searchTextBox";
this.searchTextBox.Size = new System.Drawing.Size(168, 20);
this.searchTextBox.TabIndex = 4;
this.searchTextBox.Text = "";
does not process the Backspace key. Another TextBox that is part of a
dialog box does function correctly, defined thus:
this.urlTextBox.Location = new System.Drawing.Point(8, 8);
this.urlTextBox.Name = "urlTextBox";
this.urlTextBox.Size = new System.Drawing.Size(232, 20);
this.urlTextBox.TabIndex = 0;
this.urlTextBox.Text = "";
Both were defined by the Designer, nothing fancy.
Why is the Backspace key not handled automatically in the first case? What
do I have to do to make it work? Interestingly, the Delete key does work
fine.Also interestingly, when I press the Backspace key, only the KeyUp
event is fired, not also the KeyDown and KeyPress events like most other
keys. Even if I wanted to manually handle the Backspace key within a KeyUp
event hander, I have no idea how to locate the position of the caret within
the TextBox's string. Of course, it'd be far preferable to have the TextBox
behaving normally.
Thanks,
Arun
|
|
|
|
|
So I came up with a mediocre workaround, using the OnKeyUp event handler:
private void searchTextBox_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Back)
{
if (searchTextBox.SelectionLength > 0)
searchTextBox.SelectedText = "";
else if (searchTextBox.SelectionStart > 0)
{
int caret = searchTextBox.SelectionStart;
searchTextBox.Text = searchTextBox.Text.Substring(0, caret - 1) +
searchTextBox.Text.Substring(caret);
searchTextBox.SelectionStart = caret - 1;
}
e.Handled = true;
}
}
I don't think it's a great workaround because it seems to be handled in a sluggish way. Plus, I can't hold down the Backspace key and have it delete a whole bunch of characters in a row like I can with the Backspace key.
Strangely, for this instance of the TextBox control, the Backspace key is not handled by the KeyDown or KeyPress events, unless modified by another key (e.g., Control, Shift, Alt).
Any tips would be great.
|
|
|
|
|
Hi
This one has me completely confused. What is the correct way of doing this? I have some "rules" I want to stick with.
- Designer support
- Object must be a singleton
Now these 2 are conflicting
Here's my possible solution:
public class Singleton : Component
{
private static SingletonInternal instance = null;
private static int instancecount = 0;
private class SingletonInternal : IDisposable
{
public void SomeMethod()
{
}
public void Dispose()
{
}
}
public Singleton()
{
if (instance == null)
instance = new SingletonInternal();
instancecount++;
}
public void SomeMethod()
{
instance.SomeMethod();
}
protected override void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
instancecount--;
if (instancecount == 0)
instance.Dispose();
this.disposed = true;
}
}
}
Is this the way to go? All comments welcome
Cheers
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
I think you want something along these lines...
public class Singleton : Component
{
private Singleton m_instance = null;
private Singleton(){} // constructor is private so it can't be created externally
public static Instance()
{
if(!m_instance)
m_instance = new Singleton;
return m_instance;
}
}
Your instance counting and dispose logic should still work. To use it, you dont create a new Singleton, but rather use Singleton s = Singleton.Instance();.
-pete
|
|
|
|
|
pete mcquain wrote:
private Singleton(){} // constructor is private so it can't be created externally
That is where it wont work in a designer...
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Hello,
I'm using the webbrowser control in an application where the crawling is totally automated.
The problem is that sometimes the browser try to crawl an archive file or whatever. In that case a security alert dialog box pops up and my webbrowser control waits for this dialog to close.
I already succeded removing all Javascript dialogs by implementing the IDocHostShowUI interface and by putting the control into the "silent" mode (put_silent()).
I also implemented the IDocHostUIHandler to return S_OK or S_FALSE wherever possible to get rid of a maximum of MSHTML UI unwanted behaviours.
But I still get this security alert dialogs and I have no ideas of how to avoid them.
The only solution I found for the moment is to filter the links the webbrowser control can crawl in a page by removing files containing 'zip','rar','mp3','jpg','gif'... And so on.
But this solution is not perfect because of the number of possible file types and because sometimes you can't even guess what it is from the URL.
If only the webbrowser control could allow me to access the HTTP file headers before display, to guess what it is from the content-type !
But even if I can filter the URL I crawl, I would really like a solution to remove the security alert dialogs.
I also tried to tweak the Internet Explorer options to avoid prompts and dialogs but I didn't solve this problem.
Any idea ?
Thanks,
R. LOPES
Just programmer.
|
|
|
|
|
GriffonRL wrote:
But even if I can filter the URL I crawl, I would really like a solution to remove the security alert dialogs.
I also tried to tweak the Internet Explorer options to avoid prompts and dialogs but I didn't solve this problem.
If you have an automatic crawler, why should you have anything displayed while you are crawling ? If you have anything displayed, Internet Explorer runs in "interactive" mode, and I believe ActiveX security boxes are hardwired in this mode.
It is possible to use Internet Explorer like a COM dll : see a MSDN sample called "WalkAll".
|
|
|
|
|
Hello Stephane,
If I am right WalkAll use MSHTML only not the WebBrowser control.
The problem if that I lack a lot of features if I use MSHTML instead of the WebBrowser control. I would need to implement all the navigation stuff and more.
Moreover, even if this is an antomatic crawler, I sometimes switch to some manual control.
Nevertheless thanks for the answer.
Any other idea ?
Regards,
R. LOPES
Just programmer.
|
|
|
|