|
bouli wrote:
I could do this in MFC, but Windows.Forms is so different
Actually, it's not. Underneath it all, Windows Forms makes native API calls and sends or posts, and handles window messages.
The only difference is that not all the APIs, structs, and defs are defined in headers (you can't use headers), so you must P/Invoke the native APIs and define the structs and constants you need.
For example, in your form you want to add a caption for, extend the Form class, override WndProc , and handle the WM_NCPAINT (0x0085) message in a similar fashion as you would with MFC. There's your starting point.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok, I should do the same as in MFC, create dynamically a button, paint it in the Non Client area and handle the clicks by trapping the events in the WM_SYSCOMMAND; like for MFC?
There is no spoon.
|
|
|
|
|
Yes; and as I said in my first reply, you need to P/Invoke the necessary APIs and define the necessary structs and constants. Don't forget to actually determine where the minimize button is. Don't always assume you know where it is. Depending on property values, the minimize button may be in a different location. Display settings (size of the caption buttons) may also be different.
There's quite a bit of code in C/C++/MFC available on the 'net that shows you how to do this correctly. Just try googling for it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
there is an excellent implementation in emule of such a button and this implementation also take care if xp styles are enabled or not. I am looking how it is done in emule to do something similar in C#.
thanks for the help
There is no spoon.
|
|
|
|
|
Hello Everybody,
I want to send muliple values(Array values) from one page to other.
I thing query string is not a solution. Session can be helpfull.
But some of my seniors said do not use large number of Session.
Is there any alternating way to avoid both session & query string to send array values.
Please tell me the performance effectt of Query string, Session & alternate one
Thanking You
TusharP
|
|
|
|
|
|
I have to name varibles depending on a count variable. I want to append it to the variable like int "newno" + count = new int();
This gives a syntax error I also tried takin the new value in a string, but that didn't work as well .. It said : A local variable named 'var' is already defined in this scope
when I tried string var = "newno" + count;
and
int var = new int();
HelP!!
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Hi!
What exactly are you trying to do? Are you sure you shouldn't be
using arrays of some sort instead?
An example:
string[] varArray = new string[ sizeGoesHere ];<br />
<br />
for( int i=0; i<varArray.Length; i++ )<br />
{<br />
varArray[i] = "Some Text and counter: "+i;<br />
}
Zerxes
|
|
|
|
|
A little error snuck in..
for( int i=0; i<<varArray.Length; i++ )
Zerxes
|
|
|
|
|
Ack.. That's what you get for trying to post code.
This should be correct
for( int i=0; i<varArray.Length; i++ )
Zerxes
|
|
|
|
|
ok but that's no what I'm tryin to do..
I have a variable static int count = 0; . it is global. I am adding a text box each time I click a button say..
private void btnAddCond_Click(object sender, System.EventArgs e)
{
TextBox "tb" + count = new TextBox();
this.Controls.Add("tb" + count);
}
I hope it explains my plight!!
Help PLZ
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Thought about using the Name property of TextBox class?
Otherwise i don't see a need to give your variable a unique name, because it's gone as soon as you leave the event handler.
private void btnAddCond_Click(object sender, System.EventArgs e)
{
TextBox textbox1 = new TextBox();
this.Controls.Add(textbox1);
}
|
|
|
|
|
I thank you Mr. Stefan Troschütz
Yes It works!! thankx
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
as Mr. Stefan Troschütz has stated for TextBoxes , How do you do it for a simple Integer?
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
What exactly do you want to do with your integers?
I guess storing them in some way like the textboxes
Take a look at the Collections namespace[^] which contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hashtables and dictionaries.
|
|
|
|
|
I want to name anything (integers, long, double, char etc ) which does not have a name property Dynamically.
ex.
static int count = 0;
{
int "var" + count = new int()
}
do you get what I'm tryin' to say??
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Yeah, I get but sorry this
saud_a_k wrote:
int "var" + count = new int() //you get an error on this
isn't possible.
To accomplish a similar effect you could use a SortedList[^] to store your integers whereby the key values are created by the term "var" + count.ToString() .
|
|
|
|
|
You could use an IDictionary implementation like so:
Hashtable vars = new Hashtable();
for (int i=0; i< 10; i++)
vars["newno" + i.ToString()] = i; Once your code is compiled, it cannot be changed. You either need to use Reflection Emit or the CodeDom to generate new source and compile it on the fly (Reflection Emit actually emits an assembly - no compilation necessary but it's far more complex and requires that you know and understand IL).
For your compiled code, you can only maintain the appearance of dynamic variables. This is done through collections, dictionaries, or the ComponentModel (probably not the best idea in your case). Using the approach I described above would probably be the easiest way. To get the int , then, just do int i = (int)vars["newno0"]; .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This is not exactly related to C#, sorry for the same.
The situation is, I have written a class in C#(say root.cs), if some one uses it, I want to compel the user to call 2 public methods (out of say 20 public methods written in root.cs) that he must call inorder to make the correct use of roor.cs
please guide
|
|
|
|
|
It's called a default constructor or static constructor. The static constructor runs once when the Type is first loaded, and the default constructor is (typically, depending on how you code your class) called when an instance is created:
public class Root
{
static Root()
{
}
public Root()
{
}
} If there are no other constructors or all parameterized constructors call the default constructor (add ": base()" after the constructor declaration), then there's no way the user can create the class without the default constructor being called (and there is absolutely no way for the static constructor not to be called if the Type is used).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I think my question was not written properly.
Let me explain it again.
I am trying to create/generate document in RTF format. I have written a small RTF write for the same. That has two important methods apart from several other methods.
1. CreateRTFHeader()
2. RTFEnd()
any one who wishesh to create RTF document must impliment method one at the begining(OR it can be called from the constructor with out expecting user to call it) and second method at the end.
But the second method call depends on user requirement, means the time he/she wants to conclude the document. If call is not given, the document remains syntactically imcomplete.
what to do in this situation? please guide
|
|
|
|
|
I think this is best addressed two ways:
1) Document how the person shoudl USE the library. If they don't do this, then that things will not work.
2) Use intrnal flags in the library that for example will not let you call RTFEnd unless you have first called CreateRTFHeader. It makes sense that you should be tracking some type of state internally if you are requiring the user to call things in a specific order.
There are two key rules here:
1) Tell the user how to use your code.
2) Do NOT rely on them doing what they are told.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
well said, very impressive
thanks/regards
|
|
|
|
|
You could implement the IDisposable interface and call RTFEnd (which isn't Pascal case, BTW; it should be RtfEnd to be CLS-compliant), but Ray is right: something require that you document what's required and hope people read it. If they don't, they shoot themselves in the foot.
This is not a rare request. Before executing a command in ADO.NET, a connection must be opened. Before writing to a file it must be closed. Etc. etc. You do what you can and leave it to the users to read the documents (and Ray is also right in implying that most won't - trust me). What can you do, though?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for pointing out Case Problem, but it was my mistake in typing.;)
Well, for RtfHeader() I have used internal flag that is checked in every method that inserts either text or image. If its not been called, call it first.
Actually all methods return a string in RTF format, and the document is generated in the form that used Generator class by collecting all the strings that depends on user choise, thus I am not sure about how to impliment IDisposable fot RtfEnd().
tks/rgds
|
|
|
|