|
This often comes up in the forum among object-orientation beginners. I suggest you search the forum. Basically, pass your Form1 instance to Form2, then in form2, call form1Instance.SomePublicValue to get to the value.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
The best way is to pass only the data needed to the second form before calling ShowDialog through a public property.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
Anyone know how to convert a Julian type date (example: 05189 - Format YYDDD) to a current DateTime using C#.
Thanks
|
|
|
|
|
Create a DateTime structure from the year and add the number of days less one:
new DateTime(2000 + 5, 1, 1).AddDays(189 - 1)
---
b { font-weight: normal; }
|
|
|
|
|
Hello,
I'm writing a little TabControl derivative to provide a SelectedIndexChanging event. I would like to add designer-support. I currently can create the object in the designer, but I have to implement a lot of code in the TabControlDesigner internal class (in System.Design.dll, see with .NET Reflector.)
Since it's basically a normal TabControl , I would like to avoid all the work and just use the same designer support, but the class is marked internal, so I can't specify it in the Designer attribute.
Is there a way (using reflection for example) to use this class as my designer?
[EDIT: Actually I don't need to derive from it. If I could specify it in the Designer attribute, it would be enough.]
Thanks,
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hey, i need to BOLD some words inside a string that is part of a smtpmail body.
Here is my string:
string Message_body1="User password reset " +usename +"\r\n \r\n \r\n Login information for this user has been reset. \r\n \r\n login id:" +UserName ;
I want to bold "login id:"
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
In a plain-text email, you can't. If it's an HTML email, just use the appropiate tags.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
yah, plain text.... thanks
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
You have simply to set the message type to html (MailMessage.BodyFormat = MailFormat.Html), then use html tags. To bold a word, just write: <b>your word</b>.
|
|
|
|
|
yah, but can i do that from a win form? not working on a web form
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
if you use a RichTextBox instead of a Label or TextBox, yes.
if the word you have to bold starts at position 12 (char 12) and it is long 10 chars, do that:
int oldPos = richTextBox1.SelectionStart;
richTextBox1.SelectionStart = 12;
richTextBox1.SelectionLength = 10;
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Bold);
richTextBox1.SelectionStart = oldPos;
richTextBox1.SelectionLength = 0;
richTextBox1.ScrollToCaret();
Note that oldPos is used only for restoring the old position of the blinking cursor. do that only if you need it.
I don't know any other valid way in WinForms...
|
|
|
|
|
well, sorry I didn't explain myself well... I'm using smtpMail from withing the code, no input from the user except the email address.
But none the less I was stuck in the mindset of a single line of code for the smtpmail method and forgot that if i was to declare everything with MailMessage that I could use it as MailFormat.Html, so I figgured it out.
Thanks for the memory jolt!
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
I'm creating a page with a ton of chk boxes and instead of writing out a switch or if, if, if...
is there a way to loop through them using IEnumerator ien = Panel1.controls.getEnumerator() and process only controls of a given (Check Boxes) type? I can't seem to make it work.
Thank you in advance,
Jake Holt
|
|
|
|
|
Yes.
foreach(Control ctl in panel1.Controls)
{
CheckBox chk = ctl as CheckBox;
if(chk == null)
continue;
} The as operator will make the cast if possible or return null. There's also is , but that would require two statements:
if(ctl is CheckBox)
{
CheckBox chk = (CheckBox) ctl;
...
} I hope this helps!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Works perfectly, thank you
Jake
j
|
|
|
|
|
You're welcome, I'm glad I could help
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Ok, I was really suprised at how fast this was processing using the collection versus the way I was doing it before, so naturally I decided to chop out more lines of code and put all my panels inside another panel and went about processing only the panel controls (the panels that contained the check boxes). Oddly though it only seems to find/process the last panel of three. Any ideas what would cause this?
<br />
foreach(Control ctrl in mainPanel.Controls)<br />
{<br />
Panel p = ctrl as Panel;<br />
if(p == null) continue;<br />
else<br />
{<br />
foreach(Control ctl in p.Controls)<br />
{<br />
CheckBox chk = ctl as CheckBox;<br />
if(chk == null) continue;<br />
else<br />
{<br />
if(chk.Text == "Check All" || chk.Text == "Uncheck All") continue;<br />
else<br />
{<br />
if(chk.Checked)<br />
{<br />
sql += " " + chk.Text + "=1,";<br />
}<br />
else<br />
{<br />
sql += " " + chk.Text + "=0,";<br />
}<br />
}<br />
}<br />
}<br />
}<br />
}
Thanks again, Jake
|
|
|
|
|
Seeing that you want to reduce the number of lines, I reformatted your code:
foreach(Control ctrl in mainPanel.Controls)
{
Panel p = ctrl as Panel;
if(p == null)
continue;
foreach(Control ctl in p.Controls)
{
CheckBox chk = ctl as CheckBox;
if(chk == null)
continue;
if(chk.Text == "Check All" || chk.Text == "Uncheck All")
continue;
if(chk.Checked)
{
sql += " " + chk.Text + "=1,";
}
else
{
sql += " " + chk.Text + "=0,";
}
}
} Basically, continue continues the cycle, so you don't need to do the else (and the extra braces and indenting.)
You're code looks fine. Have you stepped through it in the debugger? See what mainPanel.Control contains. Maybe your two other panels are siblings to mainPanel , or grandchildren of mainPanel .
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Ah thats it, the two that weren't processing were inside another panel. To many panels within panels. I have never been able to get the debugger to work with ASP pages =P.
Thank you again,
Jake
FYI: 264 lines of code compressed into 24.. amazing what you can do when you know what you're doing...
|
|
|
|
|
You're welcome, I'm glad I could help!
JakeHolt wrote:
FYI: 264 lines of code compressed into 24.. amazing what you can do when you know what you're doing...
It has happened to me also. You spend a full day fighting something, and you make it work. Then, a few days later you find out that you have done all of it in 5 minutes with 10 lines of code.
That's the beauty of it!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hello,
When I am switching tabs, how can I prevent the user from switching the tab unless all the textboxes on the current tab are filled in?
Is there a way of telling the index of the currently opened tab?
Thank you
|
|
|
|
|
Handle this in the SelectedIndexChanged event of the TabControl.
Live Life King Size
Alomgir Miah
|
|
|
|
|
How can I tell in what index Tab I was, and the current index Tab I am in now.
Thank you
|
|
|
|
|
Actually there is no such thing, you will have to maintain a variable yourself called previousIndex. Everytime the index changes set it. So in the next index change you can use it.
Hope this helps.
Live Life King Size
Alomgir Miah
|
|
|
|
|
But can I get a current index, inside SelectedIndexChanged event?
Thanks
|
|
|
|