|
Hy,
I have 3 pictures in a project resource, a picturebox and a button.
I want when I press the button to change dynamic the pictures from picturebox.
Can anybody help me?
thx
|
|
|
|
|
Sure, we woyld love to help. Where are you at on the task right now? Where are you stuck at?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
It's not a task is for my knowledge.
I want to place random image from the project resource to my picturebox.that's it
|
|
|
|
|
Create an array, and put the images from the project resource in it.
Image[] images = new Image[5]; Then create an object of type System.Random:
Random ran = new Random();
^ These two must be defined outside a method.
Then do the following in your button event handler:
images[0] = Properties.Resources.Image1;
images[1] = Properties.Resources.Image2;
images[2] = Properties.Resources.Image3;
images[3] = Properties.Resources.Image4;
images[4] = Properties.Resources.Image5;
int pic = ran.Next(5);
pictureBox1.Image = images[pic];
And that should do the trick.
Edit: Perhaps it would be better to fill up the array in the form's constructor (usually public Form1() ):
public Form1()
{
InitializeComponent();
images[0] = Properties.Resources.Image1;
images[1] = Properties.Resources.Image2;
}
Virtual1ty "Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"
|
|
|
|
|
I'm trying to find out how the config file works.
This is how my config file looks like now.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Settingstest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<Settingstest.Properties.Settings>
<setting name="SampleText" serializeAs="String">
<value>foo</value>
</setting>
</Settingstest.Properties.Settings>
</userSettings>
</configuration>
The Sampletext is connected to a textbox and the default value shows.
But how do I make if i want to write a new text and save it for the user, and next time I run the program the new value should show up in the textbox?
I've tried with ConfigurationManager to store the new value, but I only get System.NullReferenceException so I do something wrong.
-- modified at 13:11 Monday 15th October, 2007
|
|
|
|
|
|
Right click on your project and properties then goto settings. you can create a string there. It's a configuration property. These values are saved to your EXE' exe.config file. you can set to this string you created by doing a
your.projects.namespace.Properties.Settings.Default.YourSettingName = m_YourVariable;
Then to get the value of the settings you created you can do
m_YourVariable = your.projects.namespace.Properties.Settings.Default.YourSettingName;
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I am attempting to make a new RichTextBox class (called RTBE) which inherits from RichTextBox. One of the things I want to implement is selection graying, so setting the HideSelection property to false makes selections get a gray BackColor on loss of focus. Because I have to restore the original BackColor in the text, I am wondering if there is a faster way to get/set the SelectionBackColor property so I don't have to go through each character in the selection and obtain the color for that character (through the GUI) using RTB.Select(start, 1) followed by calling RTB.SelectionBackColor. Basically, I am hoping there is a Win API call that can get the backcolor of the text in a RTB without changing the selection. Anyone have some insight? Thanks,
Jeff
|
|
|
|
|
Take a look at the EM_GETCHARFORMAT and EM_SETCHARFORMAT message as well as the CHARFORMAT2 struct. They can be used with the RTB to enable some more functionality than what the built-in RTB gives you.
Nevertheless, these messages also work on the current selection.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I think what I will end up doing is overriding the OnPaint method, and only call the base.OnPaint when I am not figuring out what the current highlighting is. That way, my RTB doesn't flicker. Am I correct in assuming that the WinAPI calls are faster than those exposed by the RTB? If so, I may still use the SendMessage / PostMessage duo in place of the methods exposed on the control as you suggested. Thanks,
Jeff
|
|
|
|
|
I have a legacy DLL written in unmanaged C++ that I need to use in a C# application. I can use it ok, but testing shows we don't get the string information when we catch any exceptions it throws.
It throws a simple TCHAR string exception. example:
throw(_T("My Exception Message."))
We can catch it in C# with the System.Exception class, but the string message is lost. (The Message member is empty.) We tried using a RuntimeWrappedException but that did not catch it.
I can not change the code in the DLL. How can I catch these exceptions and get the string info they contain?
|
|
|
|
|
Not Knuth wrote: I can not change the code in the DLL.
But you can create a C++/CLI assembly that can 1) catch the native exception, 2) Create a managed exception and marshal the message into it 3) throw the managed exception.
|
|
|
|
|
True. And thanks for your suggestion. But I hope there is a more direct way to accomplish the same thing. Surely the designers of the framework made some provision to catch unmanged exceptions AND get the data they may contain. (Unlike the RuntimeWrappedException.)
|
|
|
|
|
Not Knuth wrote: But I hope there is a more direct way to accomplish the same thing.
I prefer to count on C++ rather than hope, but proceed as you like.
|
|
|
|
|
I prefer to use the best method available. I am not yet convinced that yours is the best method. It will work, but it is very inefficient.
|
|
|
|
|
Not Knuth wrote: but it is very inefficient.
Compared to what? It is currently your only known solution so it is the most efficient solution.
|
|
|
|
|
Following that logic, it is also the most inefficient solution!
It might turn out to be the best option. But perhaps there is another one that neither of us know. That is why I posted my question here.
|
|
|
|
|
What does the innerexception property show?
I have no blog...
|
|
|
|
|
Liam O`Hagan wrote: What does the innerexception property show?
The inner exception is null.
|
|
|
|
|
Not Knuth wrote: I can not change the code in the DLL. How can I catch these (C++) exceptions and get the string info they contain?
I have recently encountered a similar situation. After a good bit of research and testing I can tell you that the best approach is to wrap the DLL in a managed assembly where you catch the C++ exception and then throw a managed exception in its place. (As described previously in the reply from led mike.)
You can grab the string out of the C++ exception and insert it in one of the exception classes defined in the framework or in your own derived from one of them. The framework doesn't provide any method to automatically marshal the string message in a C++ exception to a managed object.
Marshall
If you continue to do the same things you always did, don't be surprised if you get the same results you always got.
|
|
|
|
|
|
Hi, I'm writing a MediaPlayer so I need to keep the monitor on and screen saver disabled during the life of my application. I understand that I need to handle certain windows messages SC_SCREENSAVE, SC_MONITORPOWER but I'm not sure how. So Please Advice
Thanks...
|
|
|
|
|
|
I got the following suggestion from someone
START
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SYSCOMMAND:
switch (wParam)
{
// disable screen saver and monitor power-saving mode
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
END
I goggled and tried to find various Constants used and replaced them with their values
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
//case WM_SYSCOMMAND: //REPLACED
case 0x0112:
switch (m.WParam.ToInt32())
{
// disable screen saver and monitor power-saving mode
//case SC_SCREENSAVE: //REPLACED
case 0xF140:
//case SC_MONITORPOWER: //REPLACED
case 0xF170:
return;
}
break;
//case WM_DESTROY: //REPLACED
case 0003:
PostQuitMessage(0); // Wont Compile in C#
return;
}
base.DefWndProc(ref m);
//return DefWindowProc(hwnd, message, wParam, lParam);
}
NOw the Function PostQuitMessage(0) wont compile and without my whole Control layout goes wrong
I checked the link you provided but being very new to Windows Programming & C# I dont know how to use all this.
So your thoughts...
Thanks...
|
|
|
|
|
Include the following in your code:
[DllImport("user32.dll")]
public external void PostQuitMessage(int returnVal);
Jeff
|
|
|
|