Friday, February 6, 2009
Running a .bat file using C# Process
Process.Start(@"C:\Program Files\Adobe\After Effects 6.5\Support Files\afterfx.exe", "-r " + path2);
Sorting 2 dimensional array/arraylist
See code snippet for an example. Let me know if you have a question.
Fernando
Fernando
1: | using System; |
Using C# how do get image size (bytes) from a image obtained from a URL
Hi,
You should download theimage first and then check the image size. I dont think there is any other option
Here is the c# code for Image/File download
You should download the
Here is the c# code for Image/File download
1: | private int DownloadImage(string link) |
Capture mouse click before control in VB.net
Copy the following code snippet your form. I got this code from the thread above and just added a public variable to store the control that the mouse is currently over.
Public Class Form2
Public myCtrlOver As String
Private WithEvents mf As New MyFilter
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Application.AddMessageFilter(mf)
End Sub
Private Sub mf_MouseMove() Handles mf.MouseMove
If Form.ActiveForm Is Me Then
Dim clientPT As Point
Dim formPT As Point = Me.PointToClient(Cursor.Position)
Dim ctlName As String
Dim ctl As Control = FindControl(Me)
If Not IsNothing(ctl) Then
ctlName = ctl.Name
clientPT = ctl.PointToClient(Cursor.Position)
Else
ctlName = Me.Name
clientPT = Me.PointToClient(Cursor.Position)
End If
' Debug.Print(ctlName & ": " & clientPT.ToString & " Form: " & formPT.ToString)
myCtrlOver = ctlName
Me.Label1.Text = ctlName
Me.Label1.Refresh()
Else
' ...WM_MOUSEMOVE is targeting a form other than this one...
End If
End Sub
Private Function FindControl(ByVal cont As Control) As Control
Dim ctl As Control = cont.GetChildAtPoint(cont.PointToClient(Cursor.Position))
If Not IsNothing(ctl) Then
If ctl.HasChildren Then
Dim subCtl As Control = FindControl(ctl)
If Not IsNothing(subCtl) Then
Return subCtl
Else
Return ctl
End If
Else
Return ctl
End If
Else
Return Nothing
End If
End Function
Private Class MyFilter
Implements IMessageFilter
Public Event MouseMove()
Private Const WM_MOUSEMOVE As Integer = &H200
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
Select Case m.Msg
Case WM_MOUSEMOVE
RaiseEvent MouseMove()
End Select
End Function
End Class
Private Sub Form2_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If myCtrlOver <> "YourMenuPanelName" Then
' Put your code here to close the menu
End If
End Sub
End Class
c# textbox validation
Question:
I have a form that contain several textboxes that are bound to a database.row that has int32 as datatype and allows dbNull value. When a user starts up the form, the code inserts three values (this is because the user needs to know these values before filling in the rest), and fills the tableadapter with data so many textboxes is bound to dbNull value.
The form has many textboxes bound to a SQL-database and the form functions very well if you put correct data into the form. I also have checks on the textboxes that must have int as datatyp that the text is possible to parse as an int (so all checks is ok).
My problem is as follows:
1. If a user "tabs" his way throug the form and accidentally puts acharacter into a textbox that must have an int they get a warning saying the textbox can only contain integers.
2. If they delete the character the textbox.validate() locks the control and I cannot get the form to do anything until the user puts in an int into the box. If the user puts in an int the validatoin works and form isunlocked again. I want it also to validate=true when textbox is empty, but I cannot seem to get this to work.
3. I want to set the textbox back to its previous state whenever the textbox.text.length == 0, because then it is the same as when you open the form and this validates fine (because it contains no data).
4.Attached code that I have to check the textboxes, but the only thing that happens is textboxSjekk.clear() and then the form locks itself because an empty textbox does not validate to int (but an empty textbox on startup does).
Hope this was understandable.
ANSWER:
implement the validating event of textboxes:
private void textBoxSjekk_Validating(object sender, CancelEventArgs e)
{
if (textBoxSjekk.Text.Length > 0)
{
try
{ Int32.Parse(textBoxSjekk.Text); }
catch (Exception)
{
MessageBox.Show("Can only contain int");
textBoxSjekk.Clear();
textBoxSjekk.Focus();
}
}
}
If you want torestore to the previous valid state of the textbox:
public partial class Form1 : Form
{
string _previousValidTextBoxSjekk;
public Form1()
{
InitializeComponent();
textBoxSjekk.Text = "2";
_previousValidTextBoxSjekk = textBoxSjekk.Text; //initialize
}
private void textBoxSjekk_Validating(object sender, CancelEventArgs e)
{
if (textBoxSjekk.Text.Length > 0)
{
int i;
if(!Int32.TryParse(textBoxSjekk.Text,out i))
{
MessageBox.Show("Can only contain int");
textBoxSjekk.Text = _previousValidTextBoxSjekk;
textBoxSjekk.Focus();
return;
}
_previousValidTextBoxSjekk = textBoxSjekk.Text; // here if you only want to restore to a populated state of the textbox once it was populated at some point in time
}
// _previousValidTextBoxSjekk = textBoxSjekk.Text ; //here if you want to add also empty as a previous valid state
}
}
I have a form that contain several textboxes that are bound to a database.row that has int32 as datatype and allows dbNull value. When a user starts up the form, the code inserts three values (this is because the user needs to know these values before filling in the rest), and fills the tableadapter with data so many textboxes is bound to dbNull value.
The form has many textboxes bound to a SQL-database and the form functions very well if you put correct data into the form. I also have checks on the textboxes that must have int as datatyp that the text is possible to parse as an int (so all checks is ok).
My problem is as follows:
1. If a user "tabs" his way throug the form and accidentally puts a
2. If they delete the character the textbox.validate() locks the control and I cannot get the form to do anything until the user puts in an int into the box. If the user puts in an int the validatoin works and form is
3. I want to set the textbox back to its previous state whenever the textbox.text.length == 0, because then it is the same as when you open the form and this validates fine (because it contains no data).
4.
Hope this was understandable.
1: | private void feilMldTall(TextBox textBoxSjekk, string feilKontroll) |
implement the validating event of textboxes:
private void textBoxSjekk_Validating(ob
{
if (textBoxSjekk.Text.Length > 0)
{
try
{ Int32.Parse(textBoxSjekk.T
catch (Exception)
{
MessageBox.Show("Can only contain int");
textBoxSjekk.Clear();
textBoxSjekk.Focus();
}
}
}
If you want to
public partial class Form1 : Form
{
string _previousValidTextBoxSjekk
public Form1()
{
InitializeComponent();
textBoxSjekk.Text = "2";
_previousValidTextBoxSjekk
}
private void textBoxSjekk_Validating(ob
{
if (textBoxSjekk.Text.Length > 0)
{
int i;
if(!Int32.TryParse(textBox
{
MessageBox.Show("Can only contain int");
textBoxSjekk.Text = _previousValidTextBoxSjekk
textBoxSjekk.Focus();
return;
}
_previousValidTextBoxSjekk
}
// _previousValidTextBoxSjekk
}
}
Get processor id using c#.net
Try this (add reference to System.Management):
publicstring GetCPUId()
{
string cpuInfo = String.Empty;
stringtemp = String.Empty;
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == String.Empty)
{// only return cpuInfo from firstCPU
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
}
return cpuInfo;
}
public
{
string
ManagementClass mc = new ManagementClass("Win32_Pro
ManagementObjectCollection
foreach (ManagementObject mo in moc)
{
if (cpuInfo == String.Empty)
{// only return cpuInfo from first
cpuInfo = mo.Properties["ProcessorId
}
}
return cpuInfo;
}
Subscribe to:
Posts (Atom)