|
Try this:
double s = p * 100 / t;
It doesn't matter what order you do divide and multiply on paper, you get the same result. However, if you divide by an int, you get an int and if it's < 1, it will round to an int, so the * 100 isn't doing what you'd hoped.
double t = double.Parse(textBox1.Text);
double s = ((p/t)*100);
or
int t = int.Parse(textBox1.Text);
double s = ((p/(double)t)*100);
would also work.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I believe that you are a former VB programmer?
In VB the / operator is only a floating point operator, and the integer division operator is \. In C# the / operator is defined for both data types, so which one is used depends on the data you use it on.
The exact equivalent of p/t in VB would in C# be (double)p/(double(t), as VB would automatically convert the values to accommodate the operator.
---
single minded; short sighted; long gone;
|
|
|
|
|
Is there any reason to cast p to double ? I thought casting t to double is all that's needed here.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yes, casting only one of the operands is the minimum required to make it work. That would decide what operator to use, so the other operator will also be cast to the same type. Whether it's done implicitly or explicitly, the generated code will be the same.
I prefer doing explicit casting in situations like this. It shows the intention of the code more clearly than if one relies on implicit conversions.
---
single minded; short sighted; long gone;
|
|
|
|
|
hi how do i get the output of a c program with csharp codes?i hav a c program which writes its outputs to a text file.. i want that output to be updated to a database through c itself or my csharp program could read that output directly somehow and save to database
aneef
|
|
|
|
|
Doesn't DllImport help you?
|
|
|
|
|
the c code im using doesnt hav a dll file..it compiles to an exe file..and besides im not much of a c developer im in to c#..ill read about dllimport as wel..thanx man
aneef
|
|
|
|
|
Can any body help me?
I have create window form using C#.There are two item that is textbox for user key in password and OK button to link new form.
What is the code to take user input in the text box.
What is the code to veryfied user input is correct with the real password. If correct link to another form and aotomaticlly close this form.If wrong automaticlly close this form.
TQ.....
|
|
|
|
|
No-oe can tell you, because we don't know where the password comes from. The best asumption is a database, in which case, a proc that returns true or false for a username/password pair is the best bet.
krajah1984 wrote: If correct link to another form and aotomaticlly close this form.If wrong automaticlly close this form.
Close(); will close a form. Is this form the main form of the app ? You could have issues here, also.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi
iam new in Tapi ,I want creat project that can Answer call and....
where I shoud Start?!!????
Can u Help
????
tanx
Mati
|
|
|
|
|
|
I have been learning C# Forms from Petzold book but it only illustrates Menu and not MenuStrip. I know how to add a separator for a Menu (new MenuItem("-")but I do not know how to add a separator for a MenuStrip. Does anyone know of a reference or can someone show me how?
// Menu items.
MenuStrip menu ;
ToolStripMenuItem menuFile ;
ToolStripMenuItem menuFileOpen ;
ToolStripMenuItem menuFileSave ;
ToolStripMenuItem menuFileSaveAs;
ToolStripMenuItem menuFileExit ;
ToolStripMenuItem menuHelp ;
ToolStripMenuItem menuHelpAbout ;
.
.
.
// Menus.
menu = new MenuStrip();
menuFile = new ToolStripMenuItem("&File" );
menuFileOpen = new ToolStripMenuItem("&Open..." , null, new EventHandler(MenuFileOpenOnClick ), Keys.Control | Keys.O);
menuFileSave = new ToolStripMenuItem("&Save" , null, new EventHandler(MenuFileSaveOnClick ), Keys.Control | Keys.S);
menuFileSaveAs = new ToolStripMenuItem("Sa&ve As..." , null, new EventHandler(MenuFileSaveAsOnClick), Keys.Control | Keys.V);
menuFileExit = new ToolStripMenuItem("&Exit" , null, new EventHandler(MenuFileExitOnClick ), Keys.Control | Keys.E);
menuHelp = new ToolStripMenuItem("&Help" );
menuHelpAbout = new ToolStripMenuItem("&About" , null, new EventHandler(MenuHelpAboutOnClick ), Keys.Control | Keys.A);
// Add items to the main menu.
menu.Items.Add(menuFile);
menuFile.DropDownItems.Add(menuFileOpen );
menuFile.DropDownItems.Add(menuFileSave );
menuFile.DropDownItems.Add(menuFileSaveAs);
menuFile.DropDownItems.Add(menuFileExit );
menu.Items.Add(menuHelp);
menuHelp.DropDownItems.Add(menuHelpAbout );
// Add the list of controls.
Controls.Add(menu);
// Assign the menu to the form.
MainMenuStrip = menu;
// Disable Save and SaveAs since there is no file open.
menuFileSave .Enabled = false;
menuFileSaveAs.Enabled = false;
|
|
|
|
|
You can use ToolStripSeparator class.
|
|
|
|
|
As advertised! That was what I was looking for. Thanks!
|
|
|
|
|
When I added the MenuStrip, I noticed that the menu is now in the client area were as Menu move the client area below the menu. Is there an easy way to fix this or is there a way to measure the MenuStrip height?
|
|
|
|
|
Hello everyone,
I am currently using this line of code to create a child form and pass the value in the constructor.
// Get the value to be passed
string parentValue = this.DataBaseName;
// Create the child form and pass the value in the constructor
this.childC = new ChildCForm(parentValue);
Could you tell me how I can pass more than one value?
Thank you very much for your help.
Khoramdin
|
|
|
|
|
just add as much as you want parameters to the constructor.....
like this........
public Class1(int intID, string strName,.........)
{
}
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
Hello khoramdin
if you want to pass more than one value in constructor you can define more than one constructor for childForm accorrding to your passed values.
such as :
public class childForm
{
public childForm(string val1)
{
}
public childForm(string val1 ,string val2)
{
}
public childForm(string val1,string val1 ,string val2)
{
}
}
and then when you create instance from childForm you must invoke the proper constructor to your values which will send from parent to child.such as:
// Get the value to be passed
string parentValue1 = this.DataBaseName1;
string parentValue2 = this.DataBaseName2;
string parentValue3 = this.DataBaseName3;
// Create the child form and pass the value in the constructor
this.childC = new ChildCForm(parentValue1,parentValue2 ,parentValue3 );
I think that's all.
|
|
|
|
|
hellow all,
in my application i need to descibe an angle from 0-360
I am looking for a visual commponent that will help me descive it
does some one have that king of thing?
thank u.
|
|
|
|
|
Hi,
I have textbox that is bound to a field in a bindingsource. The value entered into that textbox is also the same as another field in the same bindingsource. Specifically they are the initial amount of an invoice and the amount outstanding for that invoice.
The user obviously only needs to complete the one textbox but I want the same amount entered into both fields.
How can I "bind" the two fields to the same value without a lot of processing/code?
Glen Harvy
|
|
|
|
|
Any faster method to change the contrast of ab image......... OTHER than that unlock and unsafe method its very slow...... Is there anything else?????????
|
|
|
|
|
You can adjust brightness and contrast through a matrix operation in GDI+.
// return matrix for the specified contrast
public static float[][] GetContrastMatrix( int percent )
{
// perform contrast by setting the scale and offset at the same time
// calculate the scale and offset
float v = 0;
if ( percent > 0 )
{
// range from 0.0 (no change) to 3.8 (high contrast)
v = 0.0195F * percent;
v *= v;
}
else
{
// negative value, -1.0 is gray and 0.0 is no change
v = 0.009F * percent;
}
float scale = 1 + v;
float offset = v / 2;
// setup the matrix
float[][] matrix =
{
new float[]
{ scale, 0, 0, 0, 0 }, new float[]
{ 0, scale, 0, 0, 0 }, new float[]
{ 0, 0, scale, 0, 0 }, new float[]
{ 0, 0, 0, 1, 0 }, new float[]
{ -offset, -offset, -offset, 0, 1 } };
return matrix;
}
That returns a contrast matrix. This code:
ColorMatrix cm = new ColorMatrix( matrix );
ImageAttributes attr = new ImageAttributes();
attr.SetColorMatrix( cm );
Creates an ImageAttributes object that uses the matrix. Then the Graphics class has a DrawImage overload ( or more ) that take this ImageAttributes class as a parameter.
I should write an article on this, to complement my articles showing the 'lock bits' way of doing things.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanx a lot.....
Christian Graus wrote: You can adjust brightness and contrast through a matrix operation in GDI+.
Can u plz send me the matrix operation for brightness and I also want little explaination abt how these operations works....where can I find it??????
|
|
|
|
|
|
I've the following Problem. I need to populate a TreeView from a Database.
The Table looks like this:
Typename|rule.id|Rule_Prio|Level|Typename
"Vehicle","Vehicle=Car+Pickup",1,2,"car"
"Vehicle","Vehicle=Car+Pickup",1,2,"Pickup"
"car","car=carWithoutTrailer",2,1,"carWithoutTrailer"
"Truck","Truck=HeavyTruck+LightTruck",1,1,"HeavyTruck"
"Vehicle","Vehicle=Truck",2,2,"Truck"
"Truck","Truck=HeavyTruck+LightTruck",1,1,"LightTruck"
"car","car=carWithTrailer",1,1,"carWithTrailer"
"Pickup","Pickup=PickupWithoutTrailer",1,1,"PickupWithoutTrailer"
The Vehicle is the rootNode. It's no problem to get it from the Database. One of my biggest problems is: no Primary key exists for it. So it's hard for me to find a recursive solution. I think a Picture says more than words.
It should look like this:
Picture of how the Tree should look like
The Rule_Prio is always a node after nodes to group them.
Ive already created a connection to the Database. Created a DataAdapter and filled it with a DataSet which contains the Table.
Every try to build this tree leads to a stackoverflow or leads to different problems.
I read all the TreeView Tutorials in here but there recursive solutions didn't help me much because they often work on a primary key or better an id which is an int and which is autoincremented.
Any ideas?
-- modified at 6:21 Sunday 4th March, 2007
|
|
|
|
|