|
For casting between numeric types, there is a compiler option called "checked". If that is turned on, the CLR checks for loss of precision in runtime. Alternatively, you can wrap the statements you want in checked blocks (like "using" blocks) to selectively enable runtime checking.
As for general assignability, IsAssignableFrom does take into account casting up the inheritance chain IIRC.
Regards
Senthil
|
|
|
|
|
I was experimenting with the "floating window" code located in this article: http://www.vbaccelerator.com/home/NET/Code/Controls/Popup_Windows/Floating_Controls/article.asp
And i want that affect plus one additional characteristic...i want to display my form without preventing the mouse from hitting anything behind the form...as if my form wasn't their in the first place.
Would it be possible to determine what is the handle of the program that is directly beneath my form?...then i could probably send it a mousedown message with that sendmessage api.
|
|
|
|
|
YEs, the Windows API has a function to return a visible window handle from a point. Convincing it that your window does not count is obviously the problem, but the API is there.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian Graus wrote:
Convincing it that your window does not count is obviously the problem, but the API is there.
Maybe if you hide the window, call WindowFromPoint and show the window again, without letting any message pump get a message (so the other program don't get a chance to repaint itself -- I know it's preemptive multitasking, but it may just work), you could get away with it without flicker.
He would have to try that.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I looked into that API, but found it wasn't necessary to do what you were suggesting...but as expecting the flicker is crazy...even with double buffering turned on...heres code so far.
Another possibility to kill the flicker is if i can send a mouse click to a certain window handle...then i could try enumerating all windows and somehow hitting the one at that point that is also topmost of the z-order...ill then probably get rid of my mouse overrides, and handle everything in the wndproc...might be only way to avoid getting focus...this is weird heh
#region Using Directives<br />
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
using System.Runtime.InteropServices;<br />
<br />
#endregion<br />
<br />
namespace no_Mouse_input<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
#region Autostuff<br />
<br />
private System.ComponentModel.Container components = null;<br />
<br />
public Form1()<br />
{<br />
SetStyle(ControlStyles.UserPaint, true);<br />
SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
SetStyle(ControlStyles.DoubleBuffer, true);<br />
<br />
InitializeComponent();<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.SuspendLayout();<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(292, 266);<br />
this.Name = "Form1";<br />
this.Text = "Form1";<br />
this.Load += new System.EventHandler(this.Form1_Load);<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
<br />
#endregion<br />
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
this.TopMost = true;<br />
<br />
ShowFloating();<br />
}<br />
<br />
#region Floating<br />
<br />
private const int WS_EX_NOACTIVATE = 0x08000000;<br />
private const int WS_EX_TOPMOST = 0x00000008; <br />
<br />
protected override CreateParams CreateParams<br />
{<br />
get<br />
{<br />
CreateParams cp = base.CreateParams;<br />
cp.ExStyle |= (WS_EX_NOACTIVATE | WS_EX_TOPMOST);<br />
cp.Parent = IntPtr.Zero;<br />
return cp;<br />
}<br />
}<br />
<br />
<br />
private const int WM_NCHITTEST = 0x0084;<br />
private const int HTTRANSPARENT = (-1);<br />
<br />
protected override void WndProc(ref Message m)<br />
{<br />
{<br />
base.WndProc(ref m);<br />
}<br />
}<br />
<br />
[DllImport("user32")]<br />
private static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);<br />
[DllImport("user32")]<br />
private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);<br />
<br />
public void ShowFloating()<br />
{<br />
if(this.Handle == IntPtr.Zero)<br />
base.CreateControl();<br />
<br />
SetParent(base.Handle, IntPtr.Zero);<br />
ShowWindow(base.Handle, 1);<br />
}<br />
<br />
#endregion<br />
<br />
#region Faked Mouse Clicks<br />
<br />
<br />
private const int MouseEventLeftDown = 0x0002;<br />
private const int MouseEventLeftUp = 0x0004;<br />
<br />
[DllImport("user32.dll")]<br />
private static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);<br />
<br />
public void MouseLeftClick()<br />
{<br />
mouse_event(MouseEventLeftDown, MousePosition.X, MousePosition.Y, 0, 0);<br />
mouse_event(MouseEventLeftUp, MousePosition.X, MousePosition.Y, 0, 0);<br />
}<br />
<br />
public void MouseLeftDown(ref Point impact)<br />
{<br />
mouse_event(MouseEventLeftDown, impact.X, impact.Y, 0, 0);<br />
}<br />
<br />
public void MouseLeftUp(ref Point impact)<br />
{<br />
mouse_event(MouseEventLeftUp, impact.X, impact.Y, 0, 0);<br />
}<br />
<br />
#endregion<br />
<br />
#region Overrided Mouse events<br />
<br />
protected override void OnMouseDown(MouseEventArgs e)<br />
{<br />
Point screen_impact = PointToScreen(new Point(e.X, e.Y));<br />
<br />
this.Visible = false;<br />
<br />
if(e.Button == MouseButtons.Left)<br />
MouseLeftDown(ref screen_impact);<br />
<br />
this.Visible = true;<br />
}<br />
<br />
protected override void OnMouseUp(MouseEventArgs e)<br />
{<br />
Point screen_impact = PointToScreen(new Point(e.X, e.Y));<br />
<br />
this.Visible = false;<br />
<br />
if(e.Button == MouseButtons.Left)<br />
MouseLeftUp(ref screen_impact);<br />
<br />
this.Visible = true;<br />
}<br />
<br />
protected override void OnClick(EventArgs e)<br />
{ <br />
<br />
this.Visible = false;<br />
<br />
MouseLeftClick();<br />
<br />
this.Visible = true;<br />
}<br />
<br />
protected override void OnMouseWheel(MouseEventArgs e)<br />
{<br />
} <br />
<br />
#endregion<br />
}<br />
}
|
|
|
|
|
I have a page that I am generating using some System.Web.UI.Webcontrols.
On that page is a list box, a text box and a button. I want the user to place some data in the text box, click submit, and then have the list box populated depending on that data. How do I do that? (If someone just told me what I should be reading that would be great!)
Thanks a lot,
Jim
|
|
|
|
|
handle a click event for the button, and then read the data using the .Text property. How you decide to fill the list box from that is up to you.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I have two forms, Form1 and FormNew. Form1 contains a serial control. FormNew needs to write to that control. How can I do that? I am able to create an instance of FormNew and then make it pop up and work and do stuff, but now I am to the place where I wish to send commands to an embedded board via the serial port and then post the result to the text boxes.
Ideas??
Kenny O'Dell
Sr. R&D Software Engineer
Mettler-Toledo Inc.
Inman, SC
|
|
|
|
|
You need to pass an instance of Form1 to FormNew , either in the construct or as a property or even a method. It really doesn't matter:
class Form1 : Form
{
private void ShowFormNew()
{
using (FormNew form = new FormNew(this))
form.ShowDialog(this);
}
}
class FormNew : Form
{
Form1 parentForm;
private FormNew(Form1 form)
{
parentForm = form;
}
} Depending on how you open FormNew in your scenario and assign an owner to it, the Form.Owner property may be valid. Read the documentation for the Form class and its members in the .NET Framework SDK for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for the help. I'm off to the races. Hey, I have another general question. This app is using the serial port, but it would be nifty to add USB to it later. We make scales for all sorts of things, trucks, grocery store, post office, etc... Some of my designs talk HID POS. Long ago we had a contractor help us with the first deployment and he wrote the PC stuff. Now I want to do this myself in .NET C#. So the question is does someone sell a component for USB? Sort of like the Sax.Net component I use for serial?
You might be not believe it, but lots of folks still use serial, especially in the industrial world, but they are adding USB a little here and there.
Kenny O'Dell
Sr. R&D Software Engineer
Mettler-Toledo Inc.
Inman, SC
|
|
|
|
|
In the future, please start a new thread for new questions.
No, I do not have any experience with them, but you could find lots of information using a simple search[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to load the item list array in dll. I have created few dll (they have different item list in each dll).
The main program has two combo box. I would make a selection on the first combo box. Then the dll (the name based on first combo box text) will obtain the string array from the dll and automatically populate the second combo box.
I understand that I would use "late binding on native dll" method.
So is the idea of getting string array from dll possible?
|
|
|
|
|
Search this site for "plug-ins" for good articles about a similar topic, but keep in mind you can't even declare a string array in a DLL. You would have to declare it as a member of a class, either an instance or static field or property. To make this easy - if the strings are constact - declare it as a static variable using the same property name in a class with the same namespace and class name, then you could easily do something like this:
public string[] LoadArray(string path)
{
Assembly asm = Assembly.LoadFrom(path);
Type t = asm.GetType("Loader");
FieldInfo field = t.GetField("Strings");
return (String[])field.GetValue(null);
} This is a very simplistic example with no error handling so expect exceptions to be thrown. Be sure to read the documentation for the classes and members used for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello:
I have a C# project which contains a web form, which has a button calling a web page containing a crystalreportviewer, which contains a CrystalReport report; when I call this page through Response.Redirect("WebForm2.aspx"); WebForm2 is not opening, instead it is sending me an error: [Null]Reference Exception: Reference to object does not stated as object's instance.]
Somebody know what is reason of this error?
I'll thank you for your help.
A.L.
|
|
|
|
|
can anybody write a code for me to explain wats so special about a foreach loop compared to a for loop.
uni1985
|
|
|
|
|
I don't think your instructor would like that at all. Why don't you try researching it a bit.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
I think that the question would not be wholly unfounded if he is just looking ahead a bit.
In other words, maybe he is clever enough to see there is no difference at all as opposed to not understanding either. (Actually writing code though, that is a bit over the top).
uni1985 - The difference between the two is negligible. When given an array, the foreach loop is used to iterate through all of the elements of a given type. You could do something identical with the for loop. Its just more convienent.
Jim
|
|
|
|
|
Esmo2000 wrote:
I think that the question would not be wholly unfounded if he is just looking ahead a bit.
You may be right. But experience has taught me otherwise.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
Hi
Just to add one more point to what Eiso is already told. While navigating through a collection using foreach loop we cant modify the collection. Where as we can do that while using for loop.
Thanks
SGS
|
|
|
|
|
i am a beginner at this and hav been given a exercise to do to test if a word is a palindrome. a palindrome is a word that is spelt the same reversed.eg.madam,mom,dad etc.how would you go about doing it.
uni1985
|
|
|
|
|
Homework is not a palindrome.
BTW, what word have you been asked to test with?
Chris Meech
I am Canadian. [heard in a local bar]
Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Hi,
Reverse the string and compare it with the original. If they match, then the word is a palindrome.
Regards
Senthil
|
|
|
|
|
this should get you started
public bool IsPalidrome( string strWord )<br />
{<br />
string upperString = strWord.Trim().ToUpper();<br />
for ( int x = 0; x < (upperString.Length / 2); x++ )<br />
{<br />
if ( upperString[x] != upperString[upperString.Length - x - 1] )<br />
return false;<br />
}<br />
return true;<br />
}
Don't just copy and use, figure out what is going on, or you'll never learn the basics of what you need to know.
- DougW48
dwright@tdci.com
|
|
|
|
|
i have created a client server application. after installing the deployed client application, it cannot connect to the server. but it could connect when ran using the solution. do i need to add anything to the deployment project to make it work? what could be the problem?
|
|
|
|
|
myname01 wrote:
what could be the problem?
Many things. In your solution, did you connect to your server using localhost or an IP address? If so, make sure that IP address is now the address of the server.
Also, when talking to applications across machine boundaries, which is what I assume you're doing, things like firewalls often come into play. If your client application connects to the server on a specified port, make sure that the firewall on both the client and server have that port opened. This is true for both software firewalls, such as Windows XP Firewall, and hardware firewalls, such as a router. If your client is connecting to a server within the same LAN as the client, then only software firewalls will apply.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|