|
Hi sreejith,
I am able to read the duration of a movie now. thanks a lot.
I used
{
WMPLib.WindowsMediaPlayerClass sss=new WMPLib.WindowsMediaPlayerClass();
string str= @"my Path";
sss.URL=str;
sss.currentMedia.name=str;
double dur =sss.currentMedia.duration;
}
I am getting the duration here
Thanks
Vaibhav
|
|
|
|
|
Hi,
I have a textbox in a Form, which the user enters a dollar amount.
I use a try/catch statement to make sure they only entered numbers,
but I also want to stop the user from entering a number past two decimal places. In other words, if user entered 15.758, an error message (messagebox) would appear.
Ron
|
|
|
|
|
There is probably a better way but I have been using the System.Text.Regularexpressions namespace to handle the basic validation for my UI's. I create a validation object where I have different types of validation patterns that I enumerate and return true or false. I am not sure of the correct name but I believe they are called predicates. It looks like this.
I
f(validate.vString(textbox1.Text, vType.Money)
{
Do what ever I need;
}
Else
{
Notify User and handle any rollback;
}
The method will have
The regularexpresion validator takes an expression like the following.
Regex re = new Regex(@"^(?!\u00a2)\p{Sc}?(?!0,?\d)(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?"); (I pulled this off the web a few months ago and I cannot remember who wrote it but they did a good job) and then is returned by the ismatch method.
One of the features I like about this is the number of resources available to me on the web to get patterns. Since I tend to write business apps it is pretty important to me to have a flexible means of validating the inputs (decimal places, sku's, email and addresses) and so far this has worked.
Hope it helps. If you find a better way be sure and share since I am always looking to improve my apps.
It looks complicated for validation but after you get use to it and the expressions it works real well.
|
|
|
|
|
Thanks KevinMac,
I'm new to programming, so I'll have to study up on Regex.
I suppose I shouldn't use Convert.ToDecimal(txb_Tendered.Text);
for validation either.
|
|
|
|
|
hi,
For your first requirement you can use this logic on keypress event of your textbox control.
This won't take any value which is not of the numeric type.
private void txtbox_KeyPress_1(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
try
{
if (Char.IsDigit(e.KeyChar))
e.Handled=false;
else
e.Handled=true;
}
catch(Exception Ex)
{
MessageBox.Show("Invalid Entry Found","Error Description",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
And your next requirement is not professional in nature. According to me, here you are trying to force the user to do this much. You need to know one thing we can't force the user to do something that we expect. Our software need to make his life simpler. (This is only my humble suggection. And it is upto you to deside what you want.)
Why don't you do onething, after getting the user input try to format it as what ever format you want. Here is the logic for that.
textBox1.Text=Convert.ToString(float.Parse(textBox1.Text).ToString("#,##.##"));
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Hi sreejith ss nair,
first requirement:
I tried your first code, it works well except it doesn't allow user to use "." for the decimal place.
second requirement:
If the user enters 12.897, it would be an error (working with currency). Auto formating (rounding or triming) might not give the correct end result (did they want 12.89 or 12.87?).
|
|
|
|
|
hi,
Please refer Math class for how to round the values. Please gothrough the static members of Maths class.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I think this article[^] here on codeproject is what you search for. Or at least it's a good starting point.
www.troschuetz.de
|
|
|
|
|
Thanks Stefan!!!
This is what I came up with (using your link).
try
{
//Test if string will convert to a decimal
Convert.ToDecimal(txb_Tendered.Text);
//Count char. to the left of "."
int pos = txb_Tendered.Text.IndexOf(".");
if(pos != -1)// -1 would mean that no "." was entered
{
//Count characters to the right of (and including) "."
if (txb_Tendered.Text.Substring(pos).Length > 3)
{
MessageBox.Show("Don't enter more than two decimal places to the right ","Decimal Place Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
catch
{
MessageBox.Show("You must enter a valid amount for tendered (no $) ","Tendered Amount",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
|
|
|
|
|
Hi,
In C, I can code:
#define RETAIL 42
if (StoreType == RETAIL)
How do I do the same thing in C#. I find the #define but you can't assign a value to the symbol.
I suppose I could define all the StoreTypes as constants or as a property to class. Then I could say if (StoreType == StoreType.RETAIL), not sure which is the best way to go. Suggestions?
Thanks,
Glenn
|
|
|
|
|
hi,
#define ENT
#define WPK
#if ENT
// Do what ever you want
#if WPK
//do what ever you want
#endif
#elif
there is no much difference here in C# for pre-processive directives. Try to view MSDN for much reference.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Hi!
I assume you don't have only _one_ type of store, so an enumeration might be a good idea.
mav
|
|
|
|
|
Constants ara far better for what you want, so use them. Even in C
#define RETAIL 42
isn't such a good idea. One reason is that the preprocessor treats that as plain text and does search and replace on source file. You finish with no variable to debug... There are many topics on this subject.
cheers,
navi
|
|
|
|
|
Can I use an int for a C++ HANDLE?
I want to call this unmanaged function and it wants a Handle hDevice ...
/\ |_ E X E GG
|
|
|
|
|
Better to use an IntPtr for that sort of thing.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
How to change the text of a text object at runtime in crystal reports for .NET (C#)
I have done one VB.NET and works
myReport = New CrystalReport1
Dim myTextObject As CrystalDecisions.CrystalReports.Engine.TextObject
myTextObject = myReport.Section1.ReportObjects.Item("Text1")
myTextObject.Text = "New Text"
CrystalReportViewer1.ReportSource = myReport
how can i convert this to c#.
DanyBoy
|
|
|
|
|
hi,
Why don't you go for some articles. Lots and lots of good articles are there in codeproject which deals crystel reports. Try that.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Thats the answer.
C# .NET
--------
CrystalReport1 myReport = new CrystalReport1();
TextObject myTxtObj;
myTxtObj = (TextObject) myReport.ReportDefinition.ReportObjects["Text1"];
myTxtObj.Text = "testing";
crystalReportViewer1.ReportSource = myReport;
Thanks.;P
DanyBoy
|
|
|
|
|
Hi all,
Ok, I'm new to C# so if I get things wrong then please tell me
My problem is that I have a form with 4 tabs on it. One of the tabs has 2 listboxes on it with some buttons. I need to select items in the left listbox and click a button to move them to the right list box. I have achieved this with using one class (the whole app was written in one class). When I came to change something a few months later I found that with everything in one class it became hard work to read and change. So I decided to re-write it and have a different class for every tab on the form.
This is what I have written.
//from the class named, public class CODLauncher : System.Windows.Forms.Form
public void btnAddRight_Click(object sender, System.EventArgs e)
{
Maps addMap;
addMap = new Maps();
addMap.addMapToRotation();
}
//From another seperate class
public class Maps
{
public void addMapToRotation()
{
CODLauncher moveMapToRotation;
moveMapToRotation = new CODLauncher();
moveMapToRotation.lbMapRotation.Items.Add(moveMapToRotation.lbMapList.SelectedItem);
moveMapToRotation.lbMapList.Items.Remove(moveMapToRotation.lbMapRotation.SelectedItem);
}
All my classes are under the same namespace.
Thanks
|
|
|
|
|
Your objects must be referenced and must be accessible. In order to access a member of one object, you must have a reference to that object. In this case, that object is your Form derivative. In order for your second Form to reference the first, you must either pass it a reference (in the constructor or set a property or call a method), or it may have one already depending on how the second Form was opened. If it was opened from the first Form using ShowDialog(this) , then the second's Form.Owner should reference that first Form , though you'll need to cast it to your form type ((CODLauncher)this.Owner ) in order to access the field defined by CODLauncher (it's not defined on Form ).
Second, your fields lbMapList and lbMapRotation must be accessible. By default, the Visual Studio .NET (VS.NET) designer adds controls as private , meaning only that class can access the fields (that reference your controls). With a control selected, you can right-click and select "Properties", then change the Access property to something like "public" (though exposing controls directly like this isn't a good idea; you should expose the necessary properties like I've done below).
You should read Access Modifiers[^] in the Visual C# language reference for more information about access modifiers.
Here's an example of what I explained above:
using System;
using System.Drawing;
using System.Windows.Forms;
class Parent : Form
{
private TextBox txt;
private Button btn;
static void Main()
{
Application.Run(new Parent());
}
public Parent()
{
this.Text = "Example: Parent Form";
this.txt = new TextBox();
this.txt.Location = new Point(8, 8);
this.btn = new Button();
this.btn.Location = new Point(8, this.txt.Bottom + 8);
this.btn.Text = "Show Child";
this.btn.Click += new EventHandler(this.btn_Click);
this.Controls.Add(this.txt);
this.Controls.Add(this.btn);
}
private void btn_Click(object sender, EventArgs e)
{
using (Child form = new Child())
form.ShowDialog(this);
}
public string ImportantText
{
get { return this.txt.Text; }
}
}
class Child : Form
{
private Label lbl;
public Child()
{
this.Text = "Example: Child Form";
this.lbl = new Label();
this.lbl.Location = new Point(8, 8);
this.Controls.Add(this.lbl);
}
protected override void OnLoad(EventArgs e)
{
this.lbl.Text = ((Parent)this.Owner).ImportantText;
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks for the reply.
I'm off to try it, probably take me a week though
|
|
|
|
|
Hi All,
How can I use a Stored Procedure (Oracle) in C#.
can I do this, or only SQL Server?
Regards,
Kolia
Kolia
|
|
|
|
|
I don't believe that I have heard of Oracle putting this in yet. Sql Server 2005 (Yukon) has this feature. The older versions do not.
Steve Maier, MCSD MCAD
|
|
|
|
|
kolia wrote:
How can I use a Stored Procedure (Oracle) in C#.
The same way you use them in Oracle, actually, and it's supported both by the .NET 1.0 beta ADO.NET driver for Oracle, as well as the one released into .NET 1.1 and included in all future versions of .NET.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Ah... must have read that too fast. I was thinking that it was creating stored procedures that are written in C#. That and its on my mind since I am using Yukon at work now.
Steve Maier, MCSD MCAD
|
|
|
|