|
sallam
iwant to controll the lcd(lcd)
through serial port RS 232
please give some information how to do it if u know
|
|
|
|
|
Hi all!i have a read function here.I face a problem,it just can read limited byte only..Can somebody help me?Where to edit to make it read more bytes?Thank so much!
public byte[] Read(int NumBytes)
{
byte[] BufBytes; //------Declaring of dynamic Array
byte[] OutBytes; //------Declaring of dynamic Array
BufBytes = new byte[NumBytes]; //------Setting the Array Size to NumBytes( From parameter )
/*-- Check Port is Open --*/
if( hComm != INVALID_HANDLE_VALUE )
{
OVERLAPPED ovlCommPort = new OVERLAPPED(); //------Declaring of ovlCommport
int BytesRead = 0; //------Declaring of BytesRead and set to 0
ReadFile(hComm, BufBytes, NumBytes, ref BytesRead, ref ovlCommPort); //------Get data from RS232
OutBytes = new byte[BytesRead];//------Setting the size of Array to BytesRead
Array.Copy(BufBytes, OutBytes, BytesRead); //------Copy previous array data to new array data for preventing data loss
return OutBytes; //------Return the GET data
}/*-- End of Check Port is Open --*/
return null; //------Return null( nothing )
}/*-- End of Function Read --*/
|
|
|
|
|
Hello...
Try something like this:
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) != 0 /* or true (based on your interop declaration) */)
stream.write(BufBytes,0,BytesRead);
}
return stream;
}
Remark: This is code is not tested (it can contains some small bugs but the base concept will work)...
|
|
|
|
|
Hi!Thanks!This code no problem but how am i going to call it to my Main,please?Thanks again!
|
|
|
|
|
I wish to add a context menu in windows explorer which should allow me to:
1. Select multiple files and / or a combination of multiple files and folders at the same time.
2. Perform one out of 3 operations shown in the context menu (and not the default option only) depending upon where the user clicks.
I tried to search Code Project as well as Google. I am able to get sample code only for single-file selection and generally single-option (i.e., default option) from the context menu. The best sample code which comes nearest to my requirements is provided at the link
http://www.theserverside.net/articles/showarticle.tss?id=ShellExtensions[^].
However, the problem is that this is for single file selection. I tried to change it to multi-file selection, but I am yet to get success in that though I continue to make further enhancements.
Can anybody please suggest link to some code on the lines suggested by me above? Thanks in advance.
|
|
|
|
|
Hi, how can I detect my default smtp mail server?
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
Hi,
Does anyone know if it's possible to owner draw the LEFT had part of a propertygrid? Using custom UI Editors I can draw change the look of the value field, but not the name field...
Shane
|
|
|
|
|
I'm very much a novice so please make any replies idiot proof.
Here's a snippet of code I'm working on...
RegistryKey regkey;/* new Microsoft.Win32 Registry Key */
regkey = Registry.LocalMachine.CreateSubKey(@"System\CurrentControlSet\Control\Session Manager\Environment"); //Set global environment variable
regkey.SetValue("IPv4Pri", ipaddress);
Registry.LocalMachine.Flush();
SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);
Everything works great in that the registry key I wrote is in the registry and will ba available once I reboot. But I was googling and hoping that I don't have to reboot.
I'm trying to get the "SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);" thing to work and having a great amount of difficulty. It doesn't even recognize the SendNotifyMessage method.
Any insights on how I can "publish" my new registry setting so any new windows opened will have the key available?
Any help is greatly appreciated.
|
|
|
|
|
tomlog wrote:
RegistryKey regkey;/* new Microsoft.Win32 Registry Key */
regkey = Registry.LocalMachine.CreateSubKey(@"System\CurrentControlSet\Control\Session Manager\Environment"); //Set global environment variable
regkey.SetValue("IPv4Pri", ipaddress);
Registry.LocalMachine.Flush();
SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);
First of all, you should condense the first two lines into one, create and initialise in the one line.
Secondly, I suspect you need to call CreateSubKey one key at a time, this code is assuming everything except the last item already exists. That's assuming it's being written at all, as I read the rest of your post, I wonder what the problem could be ?
tomlog wrote:
I'm trying to get the "SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);" thing to work and having a great amount of difficulty. It doesn't even recognize the SendNotifyMessage method.
SendNotifyMessage is not supported in C# without pInvoke[^]. Once you import it, you can use it, but this also means that you need to use pInvoke to catch the message.
tomlog wrote:
Any insights on how I can "publish" my new registry setting so any new windows opened will have the key available?
If you wrote something to the registry then all programs can see it. The problem is letting them know, apparently.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm clueless on what pInvoke[^] is...
What would I put in my code to import/use/catch it?
Right now the regkey I write gets tot he registry and if the system is rebooted the key shows up. I'm looking for a way to not have to reboot so that my changes can be seen by any new command windows.
|
|
|
|
|
tomlog wrote:
what pInvoke[^] is...
It's a link, to a site that explains it. Basically, you put a statement in your code which works by importing a function from a dll.
tomlog wrote:
What would I put in my code to import/use/catch it?
You'd use the signature provided by that site, then you'd have a method you could call. Call it where you like.
tomlog wrote:
Right now the regkey I write gets tot he registry and if the system is rebooted the key shows up. I'm looking for a way to not have to reboot so that my changes can be seen by any new command windows.
You simply MUST be wrong. The registry does not work that way, it's instant.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I am trying to get drag and drop to work between listbox. When I have the mode set to One it works like a dream. When the mode is set to MultiExtended it fails to work and I get an IndexOutOfRangeException. The strange thing is that when I check the size of SelectedItems or SelectedIndices it shows the correct number of selected items. However, when I try to retrieve the values I get the IndexOutOfRangeException.
Another thing I discovered is that this problem only seems to occure in mouse events. If I call the same code from the event SelectedIndexChanged or from the click event of a button it does work.
Has anyone seen this behaviour before or have a solution?
Regards, nidkil
|
|
|
|
|
Could you post some code? Maybe we could see what's going wrong...
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
namespace WindowsTestApp
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private Point m_mouseDownPoint;
private int m_currentIndex;
private System.Windows.Forms.Button btnTest;
private System.Windows.Forms.ListBox lstTest_1;
private System.Windows.Forms.ListBox lstTest_2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// 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.lstTest_1 = new System.Windows.Forms.ListBox();
this.btnTest = new System.Windows.Forms.Button();
this.lstTest_2 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// lstTest_1
//
this.lstTest_1.AllowDrop = true;
this.lstTest_1.Items.AddRange(new object[] {
"Line 1",
"Line 2",
"Line 3",
"Line 4"});
this.lstTest_1.Location = new System.Drawing.Point(32, 24);
this.lstTest_1.Name = "lstTest_1";
this.lstTest_1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.lstTest_1.Size = new System.Drawing.Size(120, 95);
this.lstTest_1.TabIndex = 0;
this.lstTest_1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstTest_1_MouseDown);
this.lstTest_1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lstTest_1_MouseMove);
//
// btnTest
//
this.btnTest.Location = new System.Drawing.Point(96, 136);
this.btnTest.Name = "btnTest";
this.btnTest.Size = new System.Drawing.Size(120, 23);
this.btnTest.TabIndex = 1;
this.btnTest.Text = "Test";
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
//
// lstTest_2
//
this.lstTest_2.AllowDrop = true;
this.lstTest_2.Items.AddRange(new object[] {
"Line 1",
"Line 2",
"Line 3",
"Line 4"});
this.lstTest_2.Location = new System.Drawing.Point(168, 24);
this.lstTest_2.Name = "lstTest_2";
this.lstTest_2.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.lstTest_2.Size = new System.Drawing.Size(120, 95);
this.lstTest_2.TabIndex = 2;
this.lstTest_2.DragOver += new System.Windows.Forms.DragEventHandler(this.lstTest_2_DragOver);
this.lstTest_2.DragDrop += new System.Windows.Forms.DragEventHandler(this.lstTest_2_DragDrop);
this.lstTest_2.DragEnter += new System.Windows.Forms.DragEventHandler(this.lstTest_2_DragEnter);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(304, 182);
this.Controls.Add(this.lstTest_2);
this.Controls.Add(this.btnTest);
this.Controls.Add(this.lstTest_1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnTest_Click(object sender, System.EventArgs e)
{
Debug.WriteLine("btnTest_Click::Start");
WriteSelectedItems(lstTest_1);
}
private void lstTest_2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
Debug.WriteLine("lstTest_2_DragDrop::Start");
WriteSelectedItems(lstTest_1);
}
private void lstTest_2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
Debug.WriteLine("lstTest_2_DragEnter::Start");
// If the data is text, allow data to copied the ListBox control
if(e.Data.GetDataPresent("Text"))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void lstTest_2_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
// Retrieve the line at the specified location within the ListBox
Point pt = new Point(e.X, e.Y);
m_currentIndex = lstTest_2.IndexFromPoint(lstTest_2.PointToClient(pt));
}
private void lstTest_1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Debug.WriteLine("lstTest_1_MouseDown::Start");
m_mouseDownPoint = new Point(e.X, e.Y);
}
private void lstTest_1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
// We know the mouse is down - has it moved enough to consider it a drag?
Size dragBoxSize = SystemInformation.DragSize;
if((dragBoxSize.Width > Math.Abs(m_mouseDownPoint.X - e.X)) || (dragBoxSize.Height > Math.Abs(m_mouseDownPoint.Y - e.Y)))
{
Debug.WriteLine("lstTest_1_MouseMove::Start - Drag started");
WriteSelectedItems(lstTest_1);
// We should consider this a drag ...
lstTest_1.DoDragDrop("Test", DragDropEffects.Copy);
}
}
}
private void WriteSelectedItems(ListBox lst)
{
Debug.WriteLine("WriteSelectedItems::Start");
Debug.WriteLine("WriteSelectedItems: count=" + lst.SelectedIndices.Count);
for(int i = 0; i < lst.SelectedIndices.Count; i++)
{
try
{
Debug.WriteLine(lst.SelectedIndices[i] + "=" + lst.SelectedItems[i]);
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("Exception caught: {0}", e);
}
}
}
}
}
|
|
|
|
|
i need to compare two Image objects in this way
if(Image1 == Image2)
my question: is this comparing as well as a numerical one (int == int) or it is more binding for processor computation?
|
|
|
|
|
Sasuko wrote:
is this comparing as well as a numerical one (int == int) or it is more binding for processor computation?
I'd say operator == would simply check that both images are references to the same bitmap, it wouldn't check bit for bit if they have the same image contained in them. To do that, you could check my image processing articles. Yes, that would be computationally expensive.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am trying to add 2 buttons to each row of a data grid to allow to allow a user to add or remove a permission. The problem is I cannot seam to get access to the System.Web.UI.WebControls.DataGridCommandEventArgs to determine which button was selected. The data grid defaults to System.EventArgs e. A error comes up in the private void nitializeComponent(). How do I get the data grid control to allow the DataGridCommandEventArgs arguement.
Thanks in advance
Paul
|
|
|
|
|
Create the button with an onclick event, and set it's ID based on a property of the data source, so you can work it out from there.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi Christian:
Thanks for the reply.
When I add the button I select the Select button from the Button column in the datagrid properties. The only place I can see to set its ID is in the Command name text box in the datagrid properties. I also tried using a Delete button and Edit, Update, Cancel buttons.
Paul
|
|
|
|
|
If you're using webforms, don't use the designer, it's crap. You want to set the ID using ID=<%DataBinder.Eval("columnName")%> within the aspx code.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for your help
Paul
|
|
|
|
|
I need to create a login(registration) page using Windows Forms for redirecting different users to access data from an Access database.Could you please give me any hint about it?
|
|
|
|
|
So you want to use passwords from the Access database, from the Windows account, or of your own creation ? You're writing a Windows Forms app that uses Access for the data layer ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Actually I want for the users to put in the form their own registration data which will be written in an Access database.Thank you
|
|
|
|
|
So the passwords are stored in Access ? Then all you need is to check access to see if hte password and username match, right ? Which bit are you stuck on ?
Christian Graus - Microsoft MVP - C++
|
|
|
|