|
Hi zidan, try this. Add the code to your form class in a button event handler:
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
try
{
pictureBox1.Image = Bitmap.FromFile(openFileDialog1.FileName);
}
catch (Exception ex)
{
MessageBox.Show("Unable to load specified image: " + ex.Message, "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Also, set the Filter property of openFileDialog1 to only accept image files, e.g. 'Picture files (*.png;*.jpg)|*.png;*.jpg'
Good luck! Rob
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
Hi,
I want to check the value of DateTime like " if(dateTime != null) {//Bla bla}" but because DateTime is struct, I can't check it with null. How can I check it?
|
|
|
|
|
It can't be null, obviously. If you want a nullable type, use DateTime? if you have C# 2.0 or 3.5
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
mm yes. Thank you for your answer.
|
|
|
|
|
Hi,
if you need a special value for a DateTime (e.g. to indicate "unspecified"), you should
consider DateTime.MinValue
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi all,
In my application, i have few delegate and it is work well,but one of the delegate prompt me the error below when using delegate to pass data from frmA to frmB:
NullReferenceException was unhandled
Object reference not set to an instance of an object.
Below is the sample coding:
formA:
public openForm callbackOpenForm;
public DisplayProgramNameDate callbackProName;
public openExistingProgram callbackExistProgram;
public formA{}
private void btnOpen_open_Click(object sender, EventArgs e)
{
callbackProName(cboProgram_open.Text, Convert.ToString(DateTime.Now));
callbackOpenForm("ProgramSetting");
callbackExistProgram(); <----------------------error on this delegate
this.Hide();
}
formB:
public formB{
formA fA = new formA();
fA.callbackExistProgram += new openExistingProgram(this.callbackExistProgramFn);
}
private void callbackExistProgramFn()
{
sqlconn.DbConnection();
ds = sqlconn.SelectSQL("ProgramSetting", "PS_Program_Name", singleton.ProName);
}
class Delegate:
public delegate void CreatePictureBox(Boolean b);
public delegate void DisplayProgramNameDate(String sName, String sDate);
public delegate void openForm(String sName);
public delegate void openExistingProgram();
can anyone help me on this?
thanks in advance
cocoon
|
|
|
|
|
You need to set a breakpoint, check if the delegate itself is null. If not, step into it and work out what line in the delegate code is causing the error.
cocoonwls wrote: formA fA = new formA(); fA.callbackExistProgram += new openExistingProgram(this.callbackExistProgramFn);
Scratch that. You need to do some reading on OO. The forma inside your formb has no relation whatsoever to the instance that is running and trying to call the delegate. So, hook it up using hte instance that actually is running. And, never call a delegate without checking first if it is null.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hi Christian Graus,
Thanks for your help. I will do a checking first before call a delegate.
|
|
|
|
|
Great - that will stop the crash, but unless you hook up the right instance, it's still not going to work
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
While I am performing calculations my debug answers are showing up like 0x00000096.
Can I set a propery to display the actual numbers.
Can someone help?
Thanks.
Dougins
|
|
|
|
|
I found out that when you highlight the variable and right click you get a menu. At the bottom of the menu you can check Hexadecimal display.
Thanks everyone.
|
|
|
|
|
I have a C# app which I have behaving like an IM client; when the user selects the Windows Close button I hide the form and simply exist thru a System Tray icon. Since I'm not actually 'closing' the app, I'd like to replace the 'Close' hover text with something more appropriate like 'Hide'.
Is this possible?
Thanks
John
Jack80918
|
|
|
|
|
Hi
i think you want to do the P/Invoke or custom form control
I'm also faced this problems, then we are use the custom form.
thanks
|
|
|
|
|
Hello all.
I have a c# solution that has 4 different projects, each project has an app.config file. I am able to change the Connectionstrings section for my startup project but not for the other projects and I need to do that.
But the problem I think is that the other projects are DLL so there's no config file for them in the BIN folder and NullReference exception is thrown.
But I need to change the connectionstring at runtime
How can I achieve that?
I already tried sending the parms like this:
ModifyCnnStr("N1.Properties.Settings.DBConnection", "new cnnstr");
ModifyCnnStr("N2.Properties.Settings.DBConnection", "new cnnstr");
ModifyCnnStr("N3.Properties.Settings.DBConnection", "new cnnstr");
but it doesn't work.
This is the function i have:
namespace N1
public static class CryptConfig
{
public static bool ModifyCnnStr(string settingName, string newCnnStr)
{
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings[settingName].ConnectionString = newCnnStr;
config.Save(ConfigurationSaveMode.Full, true);
ConfigurationManager.RefreshSection("connectionStrings");
return true;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
return false;
}
}
}
}
I also tried having this class in each project but still wouldn't work. I need to use the config's connectionString because I already have lots of datasets using the connectionString.
Help please
Thanks
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class TextFile
{
public static void Main(string[] args)
{
string inFile;
string writing;
Console.WriteLine("Filename input");
Console.WriteLine("Sample: d:\\filename.LOG");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
writing = sr.ReadLine();
string onEk = " Frequencies -- ";
int i = 1;
string[] parts = null;
while (writing != null)
{
if (writing.StartsWith(onEk))
{
string transient = writing.Replace(onEk, "");
parts = transient.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
i++;
}
writing = sr.ReadLine();
}
Console.ReadLine();
sr.Close();
StreamWriter sw = new StreamWriter(@"C:\filename.LOG");
sw.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
i++;
sw.Flush();
sw.Close();
}
}
called file contents:
Frequencies -- 1093.5623 1094.7121
Red. masses -- 6.4909 1.3756
Frc consts -- 4.5735 0.9713
Frequencies -- 0.0002 0.0400
Raman Activ -- 0.0000 0.0000
Depolar (P) -- 0.7162 0.6260
Frequencies -- 0.8346 0.7700
output data:
1093.5623
1094.7121
0.0002
0.0400
0.8346
I want to write to a file, "OUTPUT DATA". But now I can be able to write to file only the END line (as a line). that is .8346 0.7700
unfortunately I want to write to file only one column all the output data.please help me
|
|
|
|
|
please help me
|
|
|
|
|
Your loop is writing each line to console, then writing the last line to your StreamWriter. Without a better description of the problem, I'd say initialize your StreamWriter before the loop and write to it instead of the Console.
Then again, I can't tell for sure what you're actually trying to do.
Visit BoneSoft.com for code generation tools (XML & XSD -> C#, VB, etc...) and some free developer tools as well.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class TextFile
{
public static void Main(string[] args)
{
string inFile;
string writing;
Console.WriteLine("Filename input");
Console.WriteLine("Sample: d:\\filename.LOG");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
writing = sr.ReadLine();
string onEk = " Frequencies -- ";
int i = 1;
string[] parts = null;
StreamWriter sw = new StreamWriter(@"C:\filename.LOG");
while (writing != null)
{
if (writing.StartsWith(onEk))
{
string transient = writing.Replace(onEk, "");
parts = transient.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
//Console.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
//i++;
sw.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
i++;
sw.Flush();
}
writing = sr.ReadLine();
}
Console.ReadLine();
sr.Close();
sw.Close();
}
}
called file contents:
Frequencies -- 1093.5623 1094.7121
Red. masses -- 6.4909 1.3756
Frc consts -- 4.5735 0.9713
Frequencies -- 0.0002 0.0400
Raman Activ -- 0.0000 0.0000
Depolar (P) -- 0.7162 0.6260
Frequencies -- 0.8346 0.7700
output data:
1093.5623 1094.7121 0.0002 0.0400 0.8346 0.7700
THANKS for reply
Finally It is writing to FILE all the line but as a line. morever there is square-zero between each two number.how can we do only one column them?
|
|
|
|
|
Problem SOLVED.BoneSoft thank you very very much :
Final CODE
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class TextFile
{
public static void Main(string[] args)
{
string inFile;
string writing;
Console.WriteLine("Filename input");
Console.WriteLine("Sample: d:\\filename.LOG");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
writing = sr.ReadLine();
string onEk = " Frequencies -- ";
int i = 1;
string[] parts = null;
StreamWriter sw = new StreamWriter(@"C:\filename.LOG");
while (writing != null)
{
if (writing.StartsWith(onEk))
{
string transient = writing.Replace(onEk, "");
parts = transient.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
//Console.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
//i++;
//sw.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
sw.WriteLine(string.Format(parts[0]));
sw.WriteLine(string.Format(parts[1]));
sw.WriteLine(string.Format(parts[2]));
i++;
sw.Flush();
}
writing = sr.ReadLine();
}
Console.ReadLine();
sr.Close();
sw.Close();
}
}
wanted output data:
1093.5623
1094.7121
0.0002
0.0400
0.8346
0.7700
I am happy
|
|
|
|
|
In the future, you can use "\r\n" instead of just "\n".
Visit BoneSoft.com for code generation tools (XML & XSD -> C#, VB, etc...) and some free developer tools as well.
|
|
|
|
|
this is the code
DataTable dt;
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
wsChattels.WebService ws = new wsChattels.WebService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
dt = this.GetCustomer();
DataRow dr = dt.NewRow();
dr[0] = txtUsername.Text;
dr[1] = txtfirstname.Text;
dr[2] = txtlastname.Text;
dr[3] = txtmobile.Text;
dr[4] = txttelephone.Text;
dr[5] = txtEmail.Text;
dt.Rows.Add(dr);
}
catch (Exception ie)
{
throw ie;
}
}
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
wsChattels.WebService ws = new wsChattels.WebService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
int i = dt.Rows.Count;
try
{
DataTable dtProperty = this.GetProperty();
DataRow drProperty = dtProperty.NewRow();
int buyingtype = Convert.ToInt32(this.ddlBuyingType.SelectedValue);
int propertytype = Convert.ToInt32(this.ddlPropertyType.SelectedValue);
int townid = Convert.ToInt32(this.ddlTown.SelectedValue);
drProperty[0] = buyingtype;
drProperty[1] = txtPropertyName.Text;
drProperty[2] = propertytype;
drProperty[3] = townid;
drProperty[4] = txtPrice.Text;
drProperty[5] = txtDescription.Text;
dtProperty.Rows.Add(drProperty);
foreach (DataRow dr in dt.Rows)
{
ws.AddNewSubmitClient(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), dr[5].ToString());
}
}
can anyone help me pls
|
|
|
|
|
I´m making a C# spelling test.
I´m having trouble with the grading process.
My idea is not having a spell check but rather compare two texts and count the errors. One text is hidden of course.
How would you think the easiest way to do this would be?
|
|
|
|
|
Out of curiosity, how will the user know what words she is supposed to spell for the test?
|
|
|
|
|
LMAO
Spelling Test, enter the correct spelling for the following words:
1) hyperbole
led mike
|
|
|
|