|
Try this article:
http://www.codeproject.com/cs/media/directxcapture.asp
It is about Audio-Video capture in DirectX, and it is awesome!
[ITA] Tozzi ha ragione: Gaia si sta liberando di noi.
[ENG] Tozzi is right: Gaia is obliterating us.
|
|
|
|
|
How can I write superscript in label in winform. I need write l.s-1. How can I do this?
Thanks
My skills:
HTML - advance
PHP - advance
MySQL - advance
Perl and Embperl - beginner
C# - beginner
PostgreSQL - beginner
3D Studio - beginner
AutoCAD - profesional
Patrik Ružič
|
|
|
|
|
I don't believe you can, unless you owner draw. A label just uses one font, and fonts do not have the ability to superscript. You can put the number on the end in a smaller font, in a new label, or owner draw ( that is, write your own label class )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace shutdown
{
///
/// Summary description for Form1.
///
public class frmshutdown : System.Windows.Forms.Form
{
internal System.Windows.Forms.GroupBox grpQuestion;
internal System.Windows.Forms.Button btnDo;
internal System.Windows.Forms.RadioButton rdbLock;
internal System.Windows.Forms.RadioButton rdbLogoff;
internal System.Windows.Forms.RadioButton rdbRestart;
internal System.Windows.Forms.RadioButton rdbShutdown;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public frmshutdown()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.grpQuestion = new System.Windows.Forms.GroupBox();
this.btnDo = new System.Windows.Forms.Button();
this.rdbLock = new System.Windows.Forms.RadioButton();
this.rdbLogoff = new System.Windows.Forms.RadioButton();
this.rdbRestart = new System.Windows.Forms.RadioButton();
this.rdbShutdown = new System.Windows.Forms.RadioButton();
this.grpQuestion.SuspendLayout();
this.SuspendLayout();
//
// grpQuestion
//
this.grpQuestion.Controls.Add(this.btnDo);
this.grpQuestion.Controls.Add(this.rdbLock);
this.grpQuestion.Controls.Add(this.rdbLogoff);
this.grpQuestion.Controls.Add(this.rdbRestart);
this.grpQuestion.Controls.Add(this.rdbShutdown);
this.grpQuestion.Location = new System.Drawing.Point(26, 56);
this.grpQuestion.Name = "grpQuestion";
this.grpQuestion.Size = new System.Drawing.Size(240, 160);
this.grpQuestion.TabIndex = 1;
this.grpQuestion.TabStop = false;
this.grpQuestion.Text = "What do you want to do?";
//
// btnDo
//
this.btnDo.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDo.Location = new System.Drawing.Point(160, 120);
this.btnDo.Name = "btnDo";
this.btnDo.Size = new System.Drawing.Size(64, 23);
this.btnDo.TabIndex = 5;
this.btnDo.Text = "Do";
this.btnDo.Click += new System.EventHandler(this.btnDo_Click);
//
// rdbLock
//
this.rdbLock.Location = new System.Drawing.Point(16, 120);
this.rdbLock.Name = "rdbLock";
this.rdbLock.Size = new System.Drawing.Size(128, 24);
this.rdbLock.TabIndex = 4;
this.rdbLock.Text = "Lock Computer";
//
// rdbLogoff
//
this.rdbLogoff.Location = new System.Drawing.Point(16, 88);
this.rdbLogoff.Name = "rdbLogoff";
this.rdbLogoff.Size = new System.Drawing.Size(128, 24);
this.rdbLogoff.TabIndex = 3;
this.rdbLogoff.Text = "Log off";
//
// rdbRestart
//
this.rdbRestart.Location = new System.Drawing.Point(16, 56);
this.rdbRestart.Name = "rdbRestart";
this.rdbRestart.Size = new System.Drawing.Size(128, 24);
this.rdbRestart.TabIndex = 2;
this.rdbRestart.Text = "Restart";
//
// rdbShutdown
//
this.rdbShutdown.Checked = true;
this.rdbShutdown.Location = new System.Drawing.Point(16, 24);
this.rdbShutdown.Name = "rdbShutdown";
this.rdbShutdown.Size = new System.Drawing.Size(128, 24);
this.rdbShutdown.TabIndex = 1;
this.rdbShutdown.TabStop = true;
this.rdbShutdown.Text = "Shutdown";
//
// frmshutdown
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.grpQuestion);
this.Name = "frmshutdown";
this.Text = "shutdown";
this.Load += new System.EventHandler(this.frmshutdown_Load);
this.grpQuestion.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new frmshutdown());
}
private void btnDo_Click(object sender, System.EventArgs e)
{
shutmode st=new shutmode();
if(rdbShutdown.Checked == true)
st.Shutdown(); //for shutdown
else if(rdbRestart.Checked == true)
st.Restart(); // Restart
else if(rdbLogoff.Checked == true)
st.LogOff(); //' Log off
else if(rdbLock.Checked ==true)
st.LockTheComputer();//' Lock Workstation
else
MessageBox.Show("Invalid option", "Illegal operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// ' Invalid Radio Button (should never been shown)
}
}
}
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
namespace shutdown
{
///
/// Summary description for shutmode.
///
public class shutmode
{
public shutmode()
{
//
// TODO: Add constructor logic here
//
}
// Constants
const int SE_PRIVILEGE_ENABLED=2;
const int TOKEN_QUERY=8;
const int TOKEN_ADJUST_PRIVILEGES=32;
const string SE_SHUTDOWN_NAME= "SeShutdownPrivilege";
//' Exit Windows Constant
const int EWX_LOGOFF = 0;
const int EWX_SHUTDOWN= 1;
const int EWX_REBOOT = 2;
const int EWX_FORCE = 4;
const int EWX_POWEROFF = 8;
const int EWX_FORCEIFHUNG= 16;
[StructLayout(LayoutKind.Sequential, Pack=1)]
//'Structure
internal struct Luid
{
public int Count;
public long luid;
public int Attr;
};
//End Structure 'TokPriv1Luid
//' Lock Workstation
[DllImport("user32.dll", ExactSpelling=true)]
static extern bool LockWorkStation();
//' Get Current Processes
[DllImport("kernel32.dll", ExactSpelling=true)]
static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", SetLastError=true)]
static extern bool OpenProcessToken(IntPtr h, int acc,IntPtr phtok);
//' Look up Priviledge Value
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern bool LookupPrivilegeValue(string host, string name,ref long luid) ;
// Adjust Token Priviledges
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, Luid newst, int len, IntPtr prev, IntPtr relen) ;
//' Exit Windows
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]
internal static extern bool ExitWindowsEx(int flg, int rea) ;
//' Exit Windows Sub
private void DoExitWindows(int flg)
{
Luid tp;
bool s;
int h1,h2;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, htok);
tp.Count = 1;
tp.luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
LookupPrivilegeValue(null, SE_SHUTDOWN_NAME,ref tp.luid);
AdjustTokenPrivileges(htok, false, tp, 0, IntPtr.Zero, IntPtr.Zero);
ExitWindowsEx(flg,0);
}
//' Shutdown
public void Shutdown()
{
DoExitWindows(EWX_SHUTDOWN);
}
// ' Restart
public void Restart()
{
DoExitWindows(EWX_REBOOT | EWX_FORCE);
}
//' Log off
public void LogOff()
{
DoExitWindows(EWX_LOGOFF);
}
//' Lock Workstation
public void LockTheComputer()
{
LockWorkStation();
}
}
}
-- modified at 1:46 Tuesday 30th August, 2005
|
|
|
|
|
It would help if instead of posting a million lines of code without comment, you told us what's wrong with it. Does it compile ? Does it do what you expect ? What do you expect ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This program is for shutdown,logoff,restart the system.
the pgm is compile without any error.
The problem is when we call the function ,for example shutdown ,the control is going to the ExitWindows()function.But its returned value is "0";so the shutdown command fails.i am unable to detect why the returned value is 0.
|
|
|
|
|
OK, that's a lot more helpful
So long as we're copying and pasting code, here's the code I found online to do this when I had the same problem as you. I think in a nutshell, some sort of privilege thing needs to happen first, which gives your app the *right* to shut down the PC.
public class Shutdown
{
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}
[DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok );
[DllImport("advapi32.dll", SetLastError=true) ]
internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid );
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool ExitWindowsEx( int flg, int rea );
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;
private static void DoExitWin( int flg )
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
}
public static void ShutDown()
{
DoExitWin( EWX_POWEROFF | EWX_FORCE );
}
}
}
Christian Graus - Microsoft MVP - C++
-- modified at 2:02 Tuesday 30th August, 2005
|
|
|
|
|
First Thanks for helping me.
I am a new programmer.So i want to know what happend inside my program(means why i am getting the return value 0 from the Exitwindows()).Expecting the reason for that thing
|
|
|
|
|
I am using the FileStream class to write and read from files. I am using it in a server to which the clients can connect and read data from the file(s). The server, on the other hand is also writing data to the files after regular intervals of time. To write the data to the file, the server creates a FileStream object in the following way:
FileStream dataStream = new FileStream(dataFileName, FileMode.Open, FileAccess.Write);
As is clear from above, the server opens the file in write only mode and it shouldn't be a problem to read from the file.
To read data from the file, following code is used:
FileStream stream = new FileStream(fileNames[i].ToString(), FileMode.Open, FileAccess.Read);
As is clear here, I open the file in read-only mode. The problem is, that if the above code executes during the time when the server has already opened the stream for writing, I get an exception (Cannot access the file as it is being used by some other process).
Any help in this regard would be highly appreciated
|
|
|
|
|
No matter how logical it seems to you, Windows will not allow it, one process needs to release the file before another can access it. In the lack of deterministic destruction, that means the using keyword, or an explicit call to Close().
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks a lot Graus for your response, but still, is there any way out of this problem?
|
|
|
|
|
Tehnoon Raza wrote:
Thanks a lot Graus for your response,
No worries. I'm interested, why do so many people respond to me by my surname ?
Tehnoon Raza wrote:
is there any way out of this problem?
As far as I am aware, no.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
No worries. I'm interested, why do so many people respond to me by my surname ?
Maybe they noticed that you are often grousing about Rent-a-coder in the lounge?
Matt Gerrans
|
|
|
|
|
Well, by default, the file is opened with Exclusive access. This means that all shared access, both read and write, is denied if another process tries to open the same file. This is actually a good thing in your situation.
If the server process is in the middle of writing to the file while your other process reads it, you could read an incomplete record or data or whatever. Your server process SHOULD hold an exclusive lock on that file when it needs to update it. What you can do, is when your other process needs to read the file, try and open it. If it's unavailable, just wait say five seconds, and try again. Keep doing that until you can finally open the file.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
let's say i have:
string a="as";
string [] id;
how do i check whether string a is inside the array? so that it returns me a bool
|
|
|
|
|
Check if IndexOf returns -1.
---
b { font-weight: normal; }
|
|
|
|
|
hi friends
u can compair string using object.toString()
otherwise use string function to comapair
if(id[0].tostring()==s)
{
}
mukesh
|
|
|
|
|
I have created a windows service and I need for that service to run at 10:00 Am and 3:00PM every day.
I tried looking into the timer control but I could not figure out as to how can I schedule a Particular time of the day since the timer intervall starts when timer starts. Can someone please help me with this? Thanks in advance.
|
|
|
|
|
Check out this article: .NET Scheduled Timer[^] Follow the link to the latest source. I'm updating the article now so all the latest article updates should be in place in the next few days.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
|
Basically there are two ways you can follow:
Either you calculate the time to the next occurrence of the wanted action and wind up a timer with this interval or you set the interval to smaller time slices (for example, once a minute) and then check the current time if it's between 10:00:00 and 10:01:00 (or 15:00:00 and 15:01:00 resp.).
Regards,
mav
|
|
|
|
|
hi friends
in c# i want to add web reference dynamic through coding.is it possible.
i am creating a client that using web refrence but i don't know where server will placed. please help me
mukesh
|
|
|
|
|
If you just want to point the web reference to a different server, you can set the dynamic property on the web reference property page. This will create an entry in the web/app config file for your project and you can change the server using that.
If that isn't dynamic enough for you you can set the Url property of the web reference proxy class before you call any methods on the proxy.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Hi all!i am using microsoft visual studio.net 2003.i have create a class for communication with serial port via RS-232.It contains read and write function.i run this in the console application.Class 1 is all the function and class 2 is my MAIN.i use Main to call the read and write function.Can someone please please help me how i can read unlimited bytes?How to call the Public MemoryStream Read(int bufSize) to my MAIN?I try it so many time but still fail to do it..Please please help me..Thanks a lot!
This is my Class 1
using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using System.Globalization;
using System.Threading;
namespace yong
{
public class port
{
/*-- Definition of variables by Programmer --*/
/*-- Setting win32 API constants --*/
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const int CREATE_ALWAYS = 2;
private const int INVALID_HANDLE_VALUE = -1;
/*-- End ofSetting win32 API constants --*/
public int PortNum = 1; //-------------Delaring of Port number to 1
public int BaudRate = 9600; //---------Set BaudRate to 9600
public byte ByteSize = 8; //-----------Set ByteSize to 8
public byte Parity = 0; //-------------0-4 = no,odd,even,mark,space
public byte StopBits = 0; //-----------0,1,2 = 1, 1.5, 2
public int ReadTimeout = 1500; //------Set TimeOut to 1500
private int hComm = -1; //-------------Declaring of comm port win32 file handle
public bool Opened = false; //---------Declaring of Opened and set to false
/*-- End of Definition of variables by Programmer --*/
[StructLayout(LayoutKind.Sequential)]
public struct DCB
{
/*-- taken from c struct in platform sdk --*/
public int DCBlength; //-----------Sizeof(DCB)
public int BaudRate; //------------Current baud rate
public uint flags; //--------------Flags
public ushort wReserved; //--------Not currently used
public ushort XonLim; //-----------Transmit XON threshold
public ushort XoffLim; //----------Transmit XOFF threshold
public byte ByteSize; //-----------Number of bits/byte, 4-8
public byte Parity; //-------------0-4 = no,odd,even,mark,space
public byte StopBits; //-----------0,1,2 = 1, 1.5, 2
public char XonChar; //------------Tx and Rx XON character
public char XoffChar; //-----------Tx and Rx XOFF character
public char ErrorChar; //----------Error replacement character
public char EofChar; //------------End of input character
public char EvtChar; //------------Received event character
public ushort wReserved1; //-------Reserved; Do not use
}/*-- End of StructLayout DCB --*/
[StructLayout(LayoutKind.Sequential)]
private struct COMMTIMEOUTS
{
public int ReadIntervalTimeout;
public int ReadTotalTimeoutMultiplier;
public int ReadTotalTimeoutConstant;
public int WriteTotalTimeoutMultiplier;
public int WriteTotalTimeoutConstant;
}/*-- End of StructLayout Commtimeout --*/
[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED
{
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;
}/*-- End of StructLayout Overlapped --*/
/*-- Importing of Kernel32.dll --*/
[DllImport("kernel32.dll")]
private static extern int CreateFile
(
string lpFileName, //--------------File name
uint dwDesiredAccess, //-----------Access mode
int dwShareMode, //----------------Share mode
int lpSecurityAttributes, //-------SD
int dwCreationDisposition, //------How to create
int dwFlagsAndAttributes, //-------File attributes
int hTemplateFile //---------------Handle to template file
);
[DllImport("kernel32.dll")]
private static extern bool GetCommState
(
int hFile, //---------Handle to communications device
ref DCB lpDCB //------Device-control block
);
[DllImport("kernel32.dll")]
private static extern bool BuildCommDCB
(
string lpDef, //------Device-control string
ref DCB lpDCB //------Device-control block
);
[DllImport("kernel32.dll")]
private static extern bool SetCommState
(
int hFile, //---------Handle to communications device
ref DCB lpDCB //------Device-control block
);
[DllImport("kernel32.dll")]
private static extern bool GetCommTimeouts
(
int hFile, //---------------------------Handle to comm device
ref COMMTIMEOUTS lpCommTimeouts //------Time-out values
);
[DllImport("kernel32.dll")]
private static extern bool SetCommTimeouts
(
int hFile, //---------------------------Handle to comm device
ref COMMTIMEOUTS lpCommTimeouts //------Time-out values
);
[DllImport("kernel32.dll")]
private static extern bool ReadFile
(
int hFile, //------------------------Handle to file
byte[] lpBuffer, //------------------Data buffer
int nNumberOfBytesToRead, //---------Number of bytes to read
ref int lpNumberOfBytesRead, //------Number of bytes read
ref OVERLAPPED lpOverlapped //-------Overlapped buffer
);
[DllImport("kernel32.dll")]
private static extern bool WriteFile
(
int hFile, //--------------------------Handle to file
byte[] lpBuffer, //--------------------Data buffer
int nNumberOfBytesToWrite, //----------Number of bytes to write
ref int lpNumberOfBytesWritten, //-----Number of bytes written
ref OVERLAPPED lpOverlapped //---------Overlapped buffer
);
[DllImport("kernel32.dll")]
private static extern bool CloseHandle
(
int hObject //-------Handle to object
);
[DllImport("kernel32.dll")]
private static extern uint GetLastError();
/*-- End of Importing of Kernel32.dll --*/
/*-- Function Open --*/
/*-- To Open the connection between 2 ports via RS232 --*/
public void Open()
{
DCB dcbCommPort = new DCB(); //------Declaring of DCB
COMMTIMEOUTS ctoCommPort = new COMMTIMEOUTS(); //------Declaring of COMMTIMEOUTS
/*-- Open Comm Port --*/
hComm = CreateFile( "COM" + PortNum ,GENERIC_READ | GENERIC_WRITE,0, 0,CREATE_ALWAYS ,0,0 ); //------Open comm port by calling dll from kernel32 and get the handle
/*-- Check port cannot be open --*/
if( hComm == INVALID_HANDLE_VALUE )
{
throw(new ApplicationException("Comm Port Can Not Be Opened"));
}/*-- End of Check port cannot be open --*/
/*-- Set the Time out property --*/
GetCommTimeouts(hComm,ref ctoCommPort);
ctoCommPort.ReadTotalTimeoutConstant = 0;
ctoCommPort.ReadTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(hComm,ref ctoCommPort);
/*-- End of Set the Time out property --*/
/*-- Setting of Baud rate, Parity, Word size and Stop bits --*/
GetCommState(hComm, ref dcbCommPort); //------Get the status of current configuration
dcbCommPort.BaudRate = BaudRate; //------Setting of baud rate
dcbCommPort.flags = 0; //------Setting of Flags
//dcbCommPort.flags = 1;//------Setting of Flags
/*-- Check parity more than 0 --*/
if(Parity > 0)
{
dcbCommPort.flags = 2; //------Setting of Flags
}/*-- End of Check parity more than 0 --*/
dcbCommPort.Parity = Parity; //------Setting of Parity
dcbCommPort.ByteSize = ByteSize; //------Setting of ByteSize
dcbCommPort.StopBits = StopBits; //------Setting of StopBits
/*-- Set property and Check for error --*/
if( !SetCommState(hComm, ref dcbCommPort) )
{
throw(new ApplicationException("Comm Port Can Not Be Opened"));
}/*-- End of Set property and Check for error --*/
/*-- End of Setting of Baud rate, Parity, Word size and Stop bits --*/
//Opened = true; //------Set Opened to true
Opened = true;
}/*-- End of Function Open --*/
/*-- Function Close --*/
/*-- Closing of Comm port --*/
public void Close()
{
/*-- Check Open handle is open --*/
if (hComm != INVALID_HANDLE_VALUE)
{
CloseHandle(hComm); //------Close port
}/*-- End of Check Open handle is open --*/
}/*-- End of Function Close --*/
/*-- Function Read --*/
/*-- For receiving of data from other parties --*/
public MemoryStream Read(int bufSize)
{
byte[] BufBytes = new byte[bufSize];
MemoryStream stream = new MemoryStream();
/*-- Check Port is Open --*/
if( hComm != INVALID_HANDLE_VALUE )
{
OVERLAPPED ovlCommPort = new OVERLAPPED();
int BytesRead = 0;
while(ReadFile(hComm, BufBytes, bufSize, ref BytesRead, ref ovlCommPort) != false /* or true (based on your interop declaration) */)
stream.Read(BufBytes,0,BytesRead);
}
return stream;
}
/*-- Function Write --*/
/*-- For transfering of data from other parties --*/
public void Write(byte[] WriteBytes)
{
/*-- Check Port is Open --*/
if( hComm != INVALID_HANDLE_VALUE )
{
OVERLAPPED ovlCommPort = new OVERLAPPED(); //------Declaring of ovlCommport
int BytesWritten = 0; //------Declaring of BytesWritten and set to 0
WriteFile(hComm, WriteBytes, WriteBytes.Length, ref BytesWritten, ref ovlCommPort); //------Transfer data to RS232
}/*-- End of Check Port is Open --*/
}/*-- End of Function Write --*/
}/*-- End of class Port --*/
}
This is my class 2
using System;
using System.Text;
using System.Threading;
namespace yong
{
public class Class2
{
static void Main(string[] args)
{
port CommPort = new port();
CommPort.Open();
while(true)
{
/*call write function*/
// Convert string to byte array and send
//string x = Console.ReadLine();
//byte[] byteDateLine = Encoding.ASCII.GetBytes( x.ToCharArray() );
//CommPort.Write(byteDateLine);
/*call read function*/
//Convert Byte to String
string sBuffer = Encoding.ASCII.GetString());
Console.WriteLine( sBuffer.ToString() );
}
}
}
|
|
|
|
|
I want to check that the text entered into a TextBox is a valid number.
I know that I can write some control structures to accomplish this but
is there a better method?
Requirements: Must accept positive, negative and decimal point.
Thanks in advance.....
|
|
|
|
|