|
Thanks Eddy, that's it.Resolved.
|
|
|
|
|
Welcome to CodeProject !
If you are at a beginning level in programming WinForms and C#, you may want to consider asking questions in the C# QA Forum, rather than in this forum; I say this based on my observation that questions with very little information about the context (lack of code, lack of information about whether it's WinForms or ASP.NET or WPF, etc.) often get a better reception in QA.
And, please do, in any future questions, give more information about what you are working with, what you have tried, and what your overall goals are.
There's one tricky part about dealing with the VisibleChanged Event of the WinForms ToolStrip: it will be fired/triggered when your Application starts, and, in that first event, the 'Visible property of the ToolStrip will be 'false, even though you did not set that Property to 'false at design-time.
Unfortunately, this fire-on-Application-start behavior only happens with certain Controls.
Here's how you deal with the possibility that your code would execute when your Application launches"
1. define a Form scoped variable: private bool intializing = true;
2. in the Form Load EventHandler set it to 'false
private bool initializing = true;
private void Form1_Load(object sender, EventArgs e)
{
initializing = false;
} 3. define a VisibleChanged EventHandler for both your ToolStrip Controls: you can do this by selecting both of them, hitting F4 in Visual Studio to bring up the Property Browser, select Events, and click on 'VisibleChanged. Or, wire-them=up individually.
private void ToolStrips_VisibleChanged(object sender, EventArgs e)
{
if (initializing || toolStrip1.Visible || toolStrip2.Visible) return;
textBox1.Location = new Point(3, 71);
textBox1.Width = 377;
textBox1.Height = 490;
label3.Location = new Point(3, 51);
} The logic here tests for whether you are initializing, or whether either one of the two ToolStrips is visible, and, if that's true, exits: else it executes your code.
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Thank you very much. Resolved.
|
|
|
|
|
I want to save data send by GPS Device using TCP/IP Port.
I want to store that that data in my database.
help me....
Code IF Possible in Vb.net or C#
|
|
|
|
|
What is your problem and where did you stuck.Did you get the data from your GPS Device.If you get the data from GPS device whats your problem with saving to Database.
|
|
|
|
|
That is not a question on how to code something, but a request for a complete project.
heyvid wrote: help me. Only if you learn to code and intend to write this yourself.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
// Server
using System;
using System.Text;
using System.Collections.Generic;
using System.Net.Sockets;
namespace OurSpiffyServer_ConsoleApp
{
class Program
{
const int Port = YourPort;
static void Main(string[] args)
{
try
{
System.Net.IPAddress serverAddress = System.Net.IPAddress.Parse(Your IP);
TcpListener listener = new TcpListener(serverAddress, Port);
listener.Start();
TcpClient ourTCP_Client = listener.AcceptTcpClient();
NetworkStream ourStream = ourTCP_Client.GetStream();
byte[] data = new byte[ourTCP_Client.ReceiveBufferSize];
int bytesRead = ourStream.Read(data, 0, System.Convert.ToInt32(ourTCP_Client.ReceiveBufferSize));
Console.WriteLine("Received : " + Encoding.ASCII.GetString(data, 0, bytesRead));
Console.ReadLine();
}
catch (Exception e) { }
}
}
}
// Client
using System;
using System.Text;
using System.Collections.Generic;
using System.Net.Sockets;
namespace consoleTCPClient
{
class Program22
{
const int ourPort = yourPort;
static void Main1(string[] args)
{
TcpClient ourMagicClient = new TcpClient();
ourMagicClient.Connect(YourIP, ourPort);
NetworkStream ourStream = ourMagicClient.GetStream();
byte[] data = Encoding.ASCII.GetBytes(" Welcome !");
ourStream.Write(data, 0, data.Length);
}
}
}
|
|
|
|
|
It was merely an observation, and that's a nice example for a TCP/IP client/server.
The easy way of getting a location would be the location api, described here[^]. Alternatively, you'd find a GPS that comes with an SDK.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Here how I would approach it.
1. work out the best data type to store the GPS info in depending on what database system you have chosen.
2. work out if you are going to be saving one or more GPS info in a transaction.
3. Connect to your database
4. save
SqlConnection[^]
SqlCommand[^]
Parameterized Query Example[^]
Hopefully this will help you solve your problem, if you are still having problems after this please postcode the code where you are having problems with and a brief explination on whats happening etc and we will help you further.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Message Removed
modified 14-Dec-14 20:44pm.
|
|
|
|
|
Hi,
I would like to get a unique ID from my computer but I am not sure if the network MAC is a good idea because many people change network cards, similarly with he hard disk so I thought if possible to get the Processor / Bios MAC address?
Is this possible? How please?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
|
get processor id is possible.
The following code will retrieve the CPU ID (processor id):
ManagementObjectCollection mbsList = null;
ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
mbsList = mbs.Get();
string id="";
foreach (ManagementObject mo in mbsList)
{
id = mo["ProcessorID"].ToString();
}
|
|
|
|
|
Today, while reading Francesco Logozzo's blog on "CodeContratcts," [^]:
I came across this interesting use of Enum:
public enum CookPasta { BoilWater, AddPasta, Stir, Strain, Done }
public const CookPasta AddOil = (CookPasta)(-1);
public void Next(CookPasta state)
{
switch (state)
{
case CookPasta.BoilWater:
break;
case AddOil:
break;
}
} And, yes, if you invoke: Next(AddOil), it hits the breakpoint.
So this appears, to me, as kind of a way to "bootleg" extending an Enum which kinds of contradicts my assumptions (as so often happens) about what Enums are and how they are compiled.
I can't imagine a use-case for this, and I suspect using the technique would lead to hard to maintain code (if the use were not documented).
I'm curious if you can see a use-case for this.
thanks, Bill
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Well...it works because an enum is a "decorated" integer, and the value of an enum variable doesn't have to be restricted to just the named values:
public enum CookPasta { BoilWater = 1, AddPasta = 2, Stir = 4, Strain = 8, Done = 16}
public const CookPasta AddOil = (CookPasta)(-1);
public void Next(CookPasta state)
{
switch (state)
{
case CookPasta.BoilWater:
break;
case AddOil:
break;
case CookPasta.AddPasta | CookPasta.Strain:
break;
case (CookPasta) 12:
break;
}
} Will compile and work just as well.
As for a use case, yes: Combined bitfields.
public const CookPasta Initialize = (CookPasta) 3;
Though I'd rather see it as
public const CookPasta Initialize = CookPasta.BoilWater | CookPasta.AddPasta;
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks for your response ! I find it interesting that I do get a design-time warning in the VS editor via a pop-up that opens if I mouse-over the "|" character about the fact the [Flags} attribute is not used, but the code certainly works fine.
My "instinctive" negative reaction to taking advantage of these "liberal" syntactic forms with Enum seems to have these components:
1. I can't ... yet ... see a clear example of a real "pay-off" ... a "big win" ... from using these forms.
2. I can imagine looking at code a year later that I wrote, or code someone else wrote, using these forms, and finding it harder to understand, maintain, and debug. imho one "benefit" of using an Enum is that it is self-documenting in a high-level way.
3. While I am just examining, with interest, such tools as Logozzo's CodeContracts, using these forms would break the CodeContracts' 'ccCheck tool (or some other AOP processing ?) which is designed to test for having all case statements that could be evaluated against the values of the Enum present.
But, what is life for but changing instinctive aversions to hypotheses, or conclusions, evaluated by clear reason
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
I can only agree with your point (2). It's nasty code - with the exception of the "or" form:
public const CookPasta Initialize = CookPasta.BoilWater | CookPasta.AddPasta;
And even then, your compiler is correct that the original enum should have the [Flags] attribute applied. (Mine doesn't, I'm still using VS2010)
And with your point (3) my standard for enum switch statements is:
public void Next(CookPasta state)
{
switch (state)
{
default: throw new ArgumentException("Unrecognised CookPasta state: " + state);
case CookPasta.BoilWater:
DoWaterBoiling();
break;
case CookPasta.AddPasta:
DoAddPasta();
break;
case CookPasta.Stir:
case CookPasta.Strain:
case CookPasta.Done:
break;
}
}
So if I add a state to the enum I will at least get an error if I forget to handle it somewhere.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I like what you just did, and I've learned something new from it, thanks.
Not to beat the dead horse into such smithereens it can't be used by the knackers, but:
When you use this "extend Enum" technique, as in: public const CookPasta AddOil = (CookPasta)(-1);
And, you have not yet written a case statement that handles 'AddOil:
The 'default case of the switch statement will be triggered if the switch statement trigger-parameter is 'AddOil. And, of course, it is unlikely you'll go to the trouble of defining something like 'AddOil unless you are going to handle it in a switch statement (or make use of it in some other way).
But, it kind of "bothers me" that you can have this kind of chimera that's "hanging there" outside the Enum. I may get over that as I digest this further; or, more likely, I'll file it and keep writing Enums the way I do now.
cheers, Bill
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
How to make a one .net method thread safe. Please explain. class class1(static public method(string,string){})
|
|
|
|
|
|
Hi,
I have a windows form that has one image with a few labels and textboxes. I designed the UI with DPI in the default setting and everything looks exactly the way I want it. When I change the DPI to 125%, the controls start overlapping each other and it looks terrible/unusable. I have tried setting the form's AutoScaleMode from None, Font, DPI, and inherit. It looks like the controls reposition and do not resize. Even though each option is a little different, changing only this one property is definitely not the solution. I checked the other controls and they do not have an AutoScaleMode property. I am using Visual Studio 2012 Pro to develop this app.
I have seen many conversations about this issue but I have yet to find a solid solution. Is there some standard way to handle this anomaly?
Thanks,
Rob
|
|
|
|
|
It is not an anomaly. Look into docking and anchoring, that'll automatically resize them as desired.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I did a quick check and all of my controls are Anchored: Top, Left by default. I noticed that Dock is set to None for the same controls. I'm looking into the Dock property now.
It doesn't look like you can use both at the same time according to MSDN:
"The Anchor and Dock properties are mutually exclusive. Only one can be set at a time, and the last one set takes precedence."
modified 15-Dec-14 14:07pm.
|
|
|
|
|
They're both used to grow/shrink the control, to fill up to empty space as designed. The form might have different dimensions on another PC, due to resolution, size of the screen and the amount of pixels per inch.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
After experimenting with the Anchor property, I have most of the form looking alright after making changes. I don't think the Dock property is going to work for this project. It seems like the labels will need to be manipulated at runtime.
Here is a link to screenshots of the different DPI states:
Screenshots with different DPI settings applied
The top screenshot is how I want it to look across any of the default Windows DPI settings if that is possible.
This is how the Anchor property is configured for each of the controls.
Image upper left - Anchor = Top, Left
Title label upper right - Anchor = Top, Right
Enter Credentials label - Anchor = Top, Left
First Name label - Anchor = Top, Left
First Name textbox - Anchor = Top, Right
Last Name label - Anchor = Top, Left
Last Name textbox - Anchor = Top, Right
Username label - Anchor = Top, Left
Username textbox - Anchor = Top, Right
Abort button - Anchor = Bottom, Right
Backup button - Anchor = Bottom, Right
Any other suggestions as to how to make this work properly?
I'm thinking at this point that I should get the current DPI setting and if it's greater than 96 dpi then move the x-coordinate of the labels.
modified 16-Dec-14 11:59am.
|
|
|
|
|