|
U can check which button is "checked" when u click on the "Done" button?
or
if u want event,
Declare a variable named answer,
public string answer;
RadioButton rdb1 = new RadioButton();
rdb1.AutoSize = true;
rdb1.Text = answers[i, 0].ToString();
rdb1.Click += new EventHandler(button_Click);
private void button_Click(object sender, EventArgs e)
{
RadioButton button = sender as RadioButton;
answer = button.Text;
}
|
|
|
|
|
Hi,
1.
you don't really need radiobutton events for this, as you already are using a "Done" button; all you need to do inside the buttonDone_Click handler, is interrogate those radiobuttons, maybe like so:
for(int i=0; i<tbp2.Controls.Length; i++) {
RadioButton rb=tbp2.Controls[i] as RadioButton;
if (rb.Checked) Console.WriteLine("RadioButton "+i+" was checked");
}
2.
I would do a couple of things differently, such as:
- instead of using some 1-dimensional and 2-dimensional array of strings, I would create a little Question class, that holds one question, all possible answers, and the correct index. It is more object-oriented that way.
- Then add instances of Question to a list of Questions.
- This would allow for a variable number of answers per question, provided you generate your RadioButtons also in a foreach loop, instead of with straight code.
- and I would consider storing all questions in a database...
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
C# Coding WindowsApplication :
1) How can I have Log for error in try catch with this informations
1.Error Name :<br />
2.Form Name:<br />
3.Function Name that error occurred :<br />
4.Date_Time when error occurred :
2) Where I save this log info.
I mean shall i save them in XML or word File ?
modified on Thursday, February 4, 2010 4:38 AM
|
|
|
|
|
|
I wanna this log for windowsApplication ?!
So Please HELP !
|
|
|
|
|
|
You are being helped. log4net is a tool to help the programmer output log statements to a variety of output targets.
http://logging.apache.org/log4net/[^]
If you want to re invent the wheel you can create a log file, for example, mylogger.logx using the StreamWriter class maybe like this:
public void Log(string Err)
{
using (StreamWriter sw = new StreamWriter("log.txt", true))
{
sw.WriteLine();
sw.WriteLine();
sw.WriteLine("NEW LOG");
sw.WriteLine("-------------------");
sw.WriteLine();
sw.WriteLine();
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
sw.WriteLine();
sw.WriteLine();
sw.WriteLine("-------------------");
sw.WriteLine();
sw.WriteLine(Err);
}
}
Then,
jojoba2010 wrote: Error Name :
assuming you caught the exception in the catch block like this
catch (Exception ex)
{
Log(ex.Message.ToString());
}
jojoba2010 wrote: Form Name:
Log(this.Text);
jojoba2010 wrote: Function Name that error occurred :
Log(ex.Source);
jojoba2010 wrote: Date_Time when error occurred :
The Log function can already do that.
Read about Exception and see the many things you can know about an exception that has occured!
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
I want the function name where this error occurred in !
I mean in which this try and catch is ?
|
|
|
|
|
Have a look at Exception.TargetSite then.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
u can get the current class and method name like this.
Below as a class variable.
private static readonly string _className =
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString();
Put below code inside each function that u want to log.
string thisMethod = _className + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()";
then whenever u want to log the info, u can just simply use
logger.info("Error Occurred + thisMethod);
|
|
|
|
|
jojoba2010 wrote: 2) Where I save this log info.
I mean shall i save them in XML or word File ?
you can save the data anyways you want it. xml is structured and easier to browse through. text is easy to implement.
jojoba2010 wrote: 1) How can I have Log for error in try catch with this informations
1.Error Name :
2.Form Name:
3.Function Name that error occurred :
4.Date_Time when error occurred :
void AddLogEntry(String errorName, String formName, String functionName)
{
DateTime entryTime = DateTime.Now;
}
or, you can do this:
void AddLogEntry(Exception ex)
{
String errorName = ex.message;
String trace = ex.StackTrace;
DateTime entryTime = DateTime.Now;
}
hope this helps and good luck
|
|
|
|
|
Hi All,
i am using DataGridView which contains 4 Columns in my c# 2005 application .
When the user types some data in Column 1 and press enter the focus should go to Column 3 (or some other column) of the same row. in short how can i do programmatically set focus to specific cell(column) in a DataGridView.
how can i achive this i serached info but not able to find any relavent data .
|
|
|
|
|
Vijjuuuuuuuuu........... wrote: in short how can i do programmatically set focus to specific cell(column) in a DataGridView
By setting the CurrentCell[^] property
I are Troll
|
|
|
|
|
Hi Eddy,
Thanks for you reply .
sorry to ask you again not clear with the example given ,
my requirment is ,focus should move to paticular cell (i will specify the row and column number) when the user is inputing the data .
|
|
|
|
|
Vijjuuuuuuuuu........... wrote: my requirment is ,focus should move to paticular cell (i will specify the row and column number) when the user is inputing the data .
You can set the input-focus using the property "CurrentCell", like this;
dataGridView1.CurrentCell = dataGridView1[3, 4];
There's a "howto" article on this subject on MSDN[^]
I are Troll
|
|
|
|
|
Thank you very much for your prompt reply .
Now i am facing new problem, celling focusing is not correct.
its is focusing one row next to mentioned index .
for example i have 4 columns for my grid.
dataGridView1.CurrentCell = dataGridView1[0,2];
for the above code the focus to [1,2]
any idea ? if not pls igorne my quesiton.
|
|
|
|
|
Hi friends,
Can you'll help me to find another way for this..
i have two bitmaps, one is the mask bitmap which is a grey scale image and another is actual image, i am applying this mask on the image, i use getpixel & setpixel to apply the color of mask image as the alpha of the other image.. for small images it is fast but it becomes slow as the image size increases.. Is there any alternate way to do so?
Thanks in advance..
Regards
Samir
|
|
|
|
|
VCsamir wrote: i use getpixel & setpixel
These methods are really VERY slow.
VCsamir wrote: Is there any alternate way to do so?
Yes.
- One of the alternative methods is to lock the bits of your bitmap in memory and perform a direct access to the bitmap bits using unsafe block. There are plenty of examples and here[^] is a very brief one.
- Another option is to hide this pointer arithmetic in a class and provide some fast GetPixel and SetPixel implementations. You can find such a class in this[^] article (it is named UnsafeBitmap ).
- The third option is using ColorMatrix[^]. Here are some examples of its usage: 1[^], 2[^]. You can find more...
I'd also suggest you to have a look at this article and the other parts of the series: Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^]
I hope this helps.
|
|
|
|
|
Thanks Sir for kind Help!!
Regards
Samir
|
|
|
|
|
You're welcome!
|
|
|
|
|
I have a problem when trying to compare two strings with different fonts.
the following comparison returns me a false result.
Assert.AreEqual("B", SomeFunction());
where
public string SomeFunction()
{
return value of a cell of Excel file using different Font;
}
in my case SomeFunction return a big big B.
Thanks for helping
|
|
|
|
|
|
We're a bit impatient today, aren't we?
It usually takes a day or two to get a reply here, as most of our members have real jobs and can't spend all their time surfing the site for questions to answer. Be more patient, and you will be rewarded.
As a beginner myself, I'm not an authority to depend on, but the first thing I noticed about your post is that your code is using Assert to do a simple comparison. I did a bit of research and found that Assert is a method used in debugging, not application code. And specifically, the .IsEqual method is really thorough, and will fail if there is anything at all different between two arguments, including fonts.
I suspect that you are trying to compare the character values, and so I wonder why you don't first cast the imported value from Excel to a string type, then use a simple if (A == B) comparison. Post a bit more of your code, and maybe you will be rewarded with a better answer.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Thank you for replying.
In my code, i use Assert.AreEqual(strA,strB) to compare two string (this function is in NUnit Framework -test driven development).
Where strA is "B" and strB = a string value returned from my SomeFunction.
Again Thanks.
|
|
|
|
|
In code a character is a character; it has no font properties. Comparing "B" to "B" will always yield equal regardless of how those characters are displayed on screen or paper.
huonghue wrote: where
public string SomeFunction()
{
return value of a cell of Excel file using different Font;
}
in my case SomeFunction return a big big B.
This is not possible unless your function is returning a bitmap image of a large character.
MVP 2010 - are they mad?
|
|
|
|