|
Worst case scenario, you can import the VisualBasic dll/namespace into yuor C# app and call the old VB methods, but ideally you shouldn't do that, even if you're using VB.
No no I would not do that. I need such functionality for a usual requirement, i.e. to clean all controls in a container. As usual I have wrote a foreach control block for looping through all the controls, depending upon controls type im planning to call its clear method or .Text = "", some controls on my form or container requires some other methods to clear them. Hence needed that function.
I think I need to dig in reflection.
Thanx for ur replies.
(In persuit of reflection)
Prasad
|
|
|
|
|
If that's all you need, then you can use as.
For example
foreach ( Control c in Controls)
{
TextBox t = c as TextBox;
if (t != null ) // c was a TextBox
{
t.Whateveryoulike
}
// and so on
}
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Great tip indeed ...
I have done by following way,
foreach(Control ctl in this.Controls)
{
if(ctl.GetType() == typeof(TextBox))
{
TextBox t=ctl as TextBox;
t.Text ="";
}
else if(ctl.GetType() == typeof(CheckBox))
{
CheckBox t=ctl as CheckBox;
t.Checked =false;
}
}
Thank you so much for ur kind help, now im feeling that im doing it in right way, and also i havent forgot to write ur name in comment of my code (alog with url to this page).
(Gr88 C# Expert)
Prasad
-- modified at 6:37 Thursday 24th August, 2006
|
|
|
|
|
Hello,
You better should go on with what Christian Graus told you.
foreach ( Control c in Controls)
{
TextBox t = c as TextBox;
if (t != null ) // c was a TextBox
{
t.Whateveryoulike
}
else
{
CheckBox cb = c as CheckBox;
if(cb!=null)
{
cb......
}
}
In youre case you ask the Type info 2 times. (takes a little longer)
(I also learned it some time ago, from Christian Graus I think)
All the best,
Martin
|
|
|
|
|
As someone said, typeof is kind of redundant. The only reason I can see to use it is that you may be able to switch on ctl.GetType(), and a switch is always better than lots of else if statements.
I'm sure that 'as' would use getType, so the most efficient way if a switch won't work would probably be to store the result of typeof(ctl) and use it without calling it every time.
-- modified at 7:11 Thursday 24th August, 2006
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanx Christian and Martin ... i would do by the way u both suggested .. i understood that it is optimum ... thanx alot
(Thinking Outside The Box)
Prasad
|
|
|
|
|
Hi All Respected Programmers
VB6 Method => Form2.Text1.Text = Form1.Text1.Text
Kindly guide me, how may I use said method in C# ?
Thank you very much in Advance
|
|
|
|
|
You need to create objects of both the forms and then u can use same code just by adding semicolon after it, such as
Form1 x=new Form1();
Form2 y=new Form2();
x.Text1.Text=y.Text1.Text;
|
|
|
|
|
The advice you were given is sort of right.
If you create new instances of Form1 and Form2, they will not relate in any way to instances that are in use in your app, so the call will do nothing, you need to use the instances that are in use, I assume you're in form1, and you want to call form2, in which case, you need the instance name for the Form2 instance, and drom Form1 entirely from the code snippet.
Your text box controls are also probably private, and instance of changing that, you should add properties that set the text of the textbox to the controls.
Also, I assume these are not your actual variable names ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
I want to be able to check which control the focus is moving to, when a particular control is losing the focus.
Bascially, I have a text box, that when you type into it displays an autocomplete list. If the focus is moving away from the text box to some other control, I want to hide the list. However, if its moving TO the list, then obviously it needs to stay shown.
There doesn't seem to be anything in the .Net events that indicate where the focus is moving. Is there perhasps a message I can send that discovers it?
Thansk in advance
phil
-- modified at 0:23 Thursday 24th August, 2006
Thanks for all your non-replies I seem to have found out how to do it..
The easiest way is to in the OnLostFocus event handler, to first call the base.OnLostFocus. When control returns to your code, whichever control the focus has moved to will now have its .Focused property = true.
<br />
protected override void OnLostFocus(EventArgs e)<br />
{<br />
base.OnLostFocus (e);
if (!autoCompleteBox.Focused)
autoCompleteBox.Hide();<br />
}<br />
Regards,
Phil
|
|
|
|
|
If you just want to hide/show the autocomplete list, you can use
event Enter and Leave from the textbox to detect GotFocus/LostFocus
|
|
|
|
|
Hello
Well! I was just typing that answer when you modified your post!!?
Anyway, I still want to add that if you are using .Net 2.0, you should use the TextBox.AutoCompleteSource property instead, which is a built in AutoComplete.
Regards
|
|
|
|
|
Hi Nader,
Yes, unfortunately this does for now need to be supported in .Net 1.1, and I don't really want to maintain two code bases.
Thanks for your reply though.
Regards,
pk
|
|
|
|
|
I've looked everywhere. I've played with the Microsoft SGML component. I've played with the .NET wrapper of the COM wrapper of Tidy HTML. I've even thought of porting my 10 year old C++ HTML parser and correcter I wrote while bored over to C#.
But I'd rather just beg, borrow or steal (or even, and I'm this desperate) buy a .NET component That Just Works.
Does anyone have any recomendations?
|
|
|
|
|
|
They both use SGMLReader, and unfortunately the implementation as it's provided HTML-encodes already encoded HTML entities within PRE tags.
ie
<pre>
>
</pre> Comes out as
<pre>
&gt;
</pre> I'm beyond patience with trying to cobble together bits and pieces. I just want a simple, effective, efficient, thread safe component with one method:
public string HtmlCleaner.ConvertHtmlToXhtml(string inputHtml);
It's gotta be out there somewhere...
|
|
|
|
|
|
I appreciate the thought but you've just demonstrated the issue at hand: if you're looking for a .NET component to convert HTML to XHTML then you're very, very limited in your choices.
I'll just slap SGMLReader into shape.
|
|
|
|
|
|
I think Html Agility Pack is related to the one at eggheadcafe, it handled the entities ok but other than a quick test I haven't used it.
|
|
|
|
|
is it possible.........!
George Batres
|
|
|
|
|
To a point. Mono is what you need, google Mono Linux and you'll find all the info you need.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yes. As Christian said you can use Mono, or you can port your .NET code to J2EE (and continue to write and debug in your .NET language) using Grasshopper from Mainsoft[^]
|
|
|
|
|
i prefer to know that in c# only what is the classes in .net that access hardware of the pc
George Batres
-- modified at 21:03 Wednesday 23rd August, 2006
|
|
|
|