|
pb.Image = temp; <----- Here....when I try and set the image.
Tom Wright
tawright915@gmail.com
|
|
|
|
|
and pb is what's null? a safe cast (the as operator) and null check would be better than C-style cast and no null check, and as long as the object names are stored correctly in the Tag s then it should work.
|
|
|
|
|
modification to my previous statement:
in order for this to work:
pb = (PictureBox)this.Controls[picBox]; the picture box needs to be parented by the main form. If it exists on a child panel or a tab control or something like that then it won't exist in the main forms control collection. You'll have to recursively search the this.Control objects to find it.
Like I said before, why not just store the picture box itself in the tag of the radio button? Then you'd have
PictureBox pb = rb.Tag as PictureBox; and you'd be done.
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
{
for (int x = 0; x < this.Controls.Count; ++x)
{
for (int y = 0; y < this.Controls[x].Controls.Count; ++y)
{
if (this.Controls[x].Controls[y].GetType() == typeof(RadioButton))
{
RadioButton _rdbtn = (RadioButton)this.Controls[x].Controls[y];
_rdbtn.CheckedChanged += new EventHandler(_rdbtn_CheckedChanged);
}
}
}
}
void _rdbtn_CheckedChanged(object sender, EventArgs e)
{
for (int x = 0; x < this.Controls.Count; ++x)
{
for (int y = 0; y < this.Controls[x].Controls.Count; ++y)
{
if (this.Controls[x].Controls[y].GetType() == typeof(RadioButton))
{
RadioButton _rdbtn = (RadioButton)this.Controls[x].Controls[y];
if (_rdbtn.Checked == true)
{
for (int z = 0; z < this.Controls[x].Controls.Count; ++z)
{
if (this.Controls[x].Controls[z].GetType() == typeof(PictureBox))
{
PictureBox _pic = (PictureBox)this.Controls[x].Controls[z];
if (_pic.Tag == "Hi")
{
}
}
}
}
}
}
}
}
Take note...
if (rb.Checked && rb.Text.Contains("Run"))
{
OnLoadPictureImage(rb.Tag.ToString(), radioButton1.Checked);
}
else
{
OnLoadPictureImage(rb.Tag.ToString(), radioButton1.Checked);
}
will always execute irrelevant true or false.
i assume one is 'Unchecked'
This code should help only if you have the radio / image / etc. on panels.
remove the 2nd layer of loops if you not using panels...
Regards,
X
Yeee
modified on Tuesday, May 19, 2009 5:17 PM
|
|
|
|
|
I see. I did not know that I had to iterate through all of the controls. Currently the Radio buttons are in group fields. I have 6 sets of Run/Stop radiobuttons on my form in 6 group fields. I ran into a problem where they were not in group fields and then only one radiobutton was allowed to be selected from the rest.
Thanks for the help.
Tom
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Hey guys, I've been googling this but with no luck
Here's what I need:
Lets say I've got a piece of plain text in a TextBox or RichTextBox, using a user specified regular expression, I need to find and copy(move to a second text box) everything that matches the said expression.
I hope that makes sense, I've got no real experience with regex so if you could point me to an article that would be great
Thanks
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Harvey Saayman wrote: so if you could point me to an article that would be great
Here you go[^]
|
|
|
|
|
|
Hello Fellow Coders;
Has anyone run across a convertor from the frequency of light to windows colors?
tia
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Rafone wrote: Has anyone run across a convertor from the frequency of light to windows colors?
I never had until you asked the question, then i did this[^]
|
|
|
|
|
Hi Everyone,
I have a combobox that i need to populate with a datasource from my database. Because i want to make this autocomplete AND have the possibility to enter new things, i have done the following:
Private void LoadAuthors()
{
cmbAuthors.DataSource = Dataset;
cmbAuthors.DisplayMember = "Name";
cmbAuthors.ValueMember = "Id";
cmdAuthors.AutoCompleteCustomSource = AutoCompleteStringCollectionIMadeFromTheDataSet;
cmbAuthors.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
cmbAuthors.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
And all is well in Autocomplete land and datasource land.. however...
to find out if they entered a new name ( and i need to pop up a form to complete extra info), i have a handler for the "leave" event on the combobox:
private void cmbAuthors_Leave(object sender, EventArgs e)
{
if (cmbAuthors.SelectedValue != null)
{
MessageBox.Show("We know the dude...");
}
else
{
MessageBox.Show("Who's that ? better make a new one !");
}
}
now the problem is:
When you leave the combobox, the selectedvalue always is null, i get the "who's that" message, and when i click ok to that THEN the selectedindex event fires on the combobox (and thus only getting the required data to make this check)
Is there any way to make sure the selectedindex event is fired first or manually fire the autocomplete so it will complete BEFORE, it actually fires the leave event ?
Any other intelligent solution i could not think of or have not found on google codeproject is welcome too obviously
Do Or Don't, there is no "try catch ex as exception end try"
|
|
|
|
|
what about trying to replace
if (cmbAuthors.SelectedValue != null)
with
if(cmbAuthors.Items.Contains(cmbAuthors.Text))
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hmm.. unfortunately, it does not even recognize that
Strange thing is, if i look at what cmbAuthors.text contains, it is the text i want..
but it does not work. so that got me thinking and i tryed:
cmbAuthors.selectedtext = cmbauthors.text;
But.. helas.. it only uses the actual typed text so for example "mad" if you are looking for madonna :s
I am thinking that autocomplete uses the same event (leave) to do it's autocomplete magic..
When i change the handler to the "onSelectedValueChanged", it does work .. however, that event get's fired multiple times on Runtime (so when binding the datasource for example)... and does not fire when the value you type in is unknown in the dataset/autocomplete
The problem is that i really have to do the check when leaving the combo ...
Do Or Don't, there is no "try catch ex as exception end try"
|
|
|
|
|
For the people that want to know.
Apparently the Leave event is fired before autocomplete can do it's magic however, Putting the handler on the LostFocus event solves the issue. It's just not visibile in the VS2005 UI...
Solved
Do Or Don't, there is no "try catch ex as exception end try"
|
|
|
|
|
I have a toolstrip and added a combobox, i wish to populate that combo box with a list of fonts that will change the font in the textbox or richtextbox.
I have searched everywhere and only found one example but it's code didn't seem to work. I have tried myself but since this is all for learning.
Im using visual c# express.
Any help will be great thanks,
Malcom
Malcom
|
|
|
|
|
If you're looking to get the list of all fonts on the system, then use something like this:
System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
foreach(FontFamily family in families)
{
if(family.IsStyleAvailable(FontStyle.Regular))
{
Font font = new Font(family, 12, FontStyle.Regular);
}
}
That gets every font style and creates a Font object from it. From there it's simple enough to add the Font name to a combo box, and hook the SelectionChanged event to create a font from its name and set the textbox's Font property
|
|
|
|
|
So in visual i create a new class and add that code in. Then i go to combobox and do the rest..?
Sorry, still getting to grips with all of this, when i first started learning i was using smallbasic.
|
|
|
|
|
That code will get a list of every installed font in the system. Double click on the Form, and you'll get a method called xxx_Load, where xxx is the name of your Form (not the Text property, that's just the caption). Put the code in there (don't forget to add a using System.Drawing statement at the top of your code file), but just after the line with new Font(..) in it, add an item to the combobox with the text of font.Name
That lists the fonts used in the combobox. When you want to set the textbox's Font property, double click in the combobox, and put some code in there which creates a Font (using new) from the SelectedItem property of the combobox. Set the textbox's Font property to that Font object you just created
|
|
|
|
|
Ok, thanks alot ill give it a shot
edit: the word 'famlies' "foreach(FontFamily family in families)"
is underlined in red: word does not exist in current context.
Sorry again, ive added the using system statement etc, wont go away.
edit: before i start to annoy you maybe i presented this out wrong. I created a project just to try this out and see if i can get it working. Thats why i still have all the names like form1 :P
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Text;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
foreach (FontFamily family in families)
{
if (family.IsStyleAvailable(FontStyle.Regular))
{
Font font = new Font(family, 12, FontStyle.Regular);
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
modified on Tuesday, May 19, 2009 11:53 AM
|
|
|
|
|
the error is that 'families' does not exist. change it to 'fonts'. Its a mistake in the code
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Even with that error fixed the code you have posted wont do what you want.
so here are the fixes, the should work...
1. in you load event change the 'families' to 'fonts'
2. just before you foreach loop add the following line...
comboBox1.Items.Clear();
3. inside your foreach loop replace all code with this line only...
comboBox1.Items.Add(family.Name);
this should then populate you combo box with all the fonts
4. in your selected index changed event add the following code to alter you textbox font...
textbox1.Font = new Font(comboBox1.Text, 10);
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I get a error:
foreach statement cannot operate on variables of type 'System.Drawing.Text.InstalledFontCollection' because <'System.Drawing.Text.InstalledFontCollection' does not contain a public definition for 'GetEnumerator' ...................................
Thats after foreach (FontFamily family in fonts) - changing it from 'family' to 'fonts'
This is so much harder than small basic but i like challenges, ones that not go so well
|
|
|
|
|
Change the foreach from fonts to fonts.Families
|
|
|
|
|
Whoops. I took the code from one of my snippets, so had to adapt it for some reason. Don't worry though, I'm not annoyed in the slightest. You're trying to learn, and that's always a good thing
|
|
|
|
|
Have you tried FontDialog? I dont know if its useful for u:
using System.Windows.Forms;
FontDialog fontDialog = new FontDialog();
if ( fontDialog.ShowDialog() != DialogResult.Cancel )
{
textBox.Font = fontDialog.Font;
}
|
|
|
|