|
This may work depending on the input string:
string colorName = "Black";
SolidBrush brush = new SolidBrush(Color.FromName(colorName));
You can find a list of available colors here[^].
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks Greeeg.
This code doesn't work in WPF.
I'm using WPF !
Freshman
|
|
|
|
|
Well, he's given you the only possible answer. That's how you get a color from a string, you need to build whatever brush type you need from there.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
|
I may have misread your question?
In code:
ComboBox comboBox1 = new ComboBox();
Brush backgroundBrush = Brushes.Black;
this.comboBox1.Background = backgroundBrush;
In Xaml:
comboBox1 background="Black"
|
|
|
|
|
I would like our project DLL’s placed into a sub-folder(\plugins). But when I try to run the application, it can’t find them.
In the reference paths, I added a relative search path (.\plugins) and tried a micro path ($(TargetPath\plugins)). Neither seems to work. Unless the dll is in the same directory, I get an exception. The exceptions are the same. Can’t find file.
Thanks
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
By default, your application looks for its assemblies in one directory, so the exe and the dlls should be in the same directory. If you want to do something different then you have to take over the whole lifecycle of the assembly. In other words, you need to look at Assembly.Load .
|
|
|
|
|
After research I also found that you can give the X.exe an X.exe.config file that defines other sub-folders to search.
This works for me.
Thanks
Glenn
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
hi friends,
i have 16 images in my form, but what i want is to access them by an index or something that makes it easy to call them. i don't want to call them their name (which is clearly diffrent from an other) each time. i want to make an array of them. how can i do that?
generally, how can i achive the controls (such as buttons, textboxes, etc) in my form?
is there any 'foreach'-like way?
thanks
modified on Tuesday, July 1, 2008 3:45 PM
|
|
|
|
|
Well, you could use one of the many array or list type structures that .NET supports. You could always implement this by creating a generic List of your images, which can be iterated over with a minimum of fuss. For example:
List<Image> images = GetImagesFromDb();
foreach (Image img in images)
{
}
|
|
|
|
|
I have to fill the list each time the programs starts, but for this, i have to get the name of each picture and write a line of code for adding each to list.
Imagine i have dragged some PictureBox from toolbox in design form. now i want them without calling their name. i want them in in an array. how is it? or something like this:
foreach(Object obj in ...)
if (obj is Image) MessageBox.Show("this is an image");
what should i write in blank?
thanks for your answer
|
|
|
|
|
Do you mean something like this?
foreach (Control c in this.Controls)
{
PictureBox pic = c as PictureBox;
if (pic != null)
...
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
yes, thank you. that can be what i was looking for
|
|
|
|
|
|
thank you but isn't the ImageSize of pictures limited (256 * 256)? what is the solution? how can i have something like ImageList but with much bigger size of image?
thanks again
|
|
|
|
|
Do you need to display the images or just keep track of them inside a list?
If you need to display them, then you could add PictureBox controls dynamically to the form at runtime, something like
PictureBox pic = new PictureBox();
pic.Image = ...;
Controls.Add(pic);
If you just need a list then this will do the trick:
List<Image> images = new List<Image>();
images.Add(...);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
i can solve my problem now but it is not optimized though :
i named my pictureboxes as: picturebox1, picturebox2, ... and picturebox16. now i want them in a list. i wrote the followings:
PictureBox pic;
for (int i = 1; i < 16; i++)
{
foreach (Control cont in this.Controls)
{
if (cont is PictureBox)
{
pic = cont as PictureBox;
if (pic.Name.EndsWith(i.ToString()))
images.Add(pic);
}
}
}
it works but do you suggest any thing more optimized?
thanks
|
|
|
|
|
Optimized? This is plain wrong
Right now your code will be executed 16 * Controls.Length times.
The inner foreach loop will be executed for each i in the outer loop.
Better keep a counter in the foreach loop like this:
int picCounter = 1;
foreach (Control cont in this.Controls)
{
if (cont is PictureBox)
{
pic = cont as PictureBox;
if (pic.Name.EndsWith(picCounter.ToString()))
images.Add(pic);
picCounter++;
}
}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
imagine the first control which is surveyed in foreach loop is picturebox16 (foreach is surveying the controls from picturebox16 to picturebox1 in order). then every time, the if condition fails. because picCounter is 1 and non of the name of picture boxes ends with "1" (11 is exception here). so only picturebox1 (last survey of foreach) is added to the List (because if condition does not fail). and after that, the foreach loop is finished (because there is no other control in foreach to survey) and only picturebox1 is added to the list.
so i think it is better to change the value of picCounter and then start foreach from the first. isn't it right? please guide me.
thanks
|
|
|
|
|
Ah, I see.
Why do you actually need the pic.Name.EndsWith check?
For me it seems like you just want to store each PictureBox control into a list.
Or do you have more picture boxes that do not end with a number 1-16?
If this is the case, then I'd store the picture box number into the Tag property, so you only have to check this property if you want to add the PictureBox to the list.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
as you said, tag is more proper here.
isn't it any way more optimized than those tow loops? where they correct or not at last? how can i make it optimized (with consideration that i use tags instead of EndsWith)
thanks again
|
|
|
|
|
I think the Tag solution with just the foreach loop is the correct way to do this.
As you said yourself, your solution will add some controls twice or some none at all (depending whether you continue out of the loop or not), because EndsWith("1") would trigger for both pictureBox1 and pictureBox11, depending on the order in which the picture boxes are returned in the foreach loop.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
except the Tag solution, do you offer anything else?
why just 'foreach'? you mean without the extern 'for'? i can't find out why. i wonder if you explain more about the reason of ommiting the extern 'for'.
thanks again and again
|
|
|
|
|
Sajjad Izadi wrote: except the Tag solution, do you offer anything else?
I'd say it's the best solution for your problem.
Sajjad Izadi wrote: why just 'foreach'? you mean without the extern 'for'? i can't find out why.
Because using the Tag, the foreach loop will already find all the controls you are looking for.
foreach (Control cont in this.Controls)
{
if (cont is PictureBox)
{
pic = cont as PictureBox;
if(pic != null)
{
string tag = pic.Tag as string;
int number = int.Parse(tag);
if (tag != null && number >= 1 && number <= 16)
Console.WriteLine(number);
}
}
}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
but i want the pictures in order of their position at form. does it response for the order?
and a non related question: what is that 'int?' ?
|
|
|
|