Diamonddrake 397 Master Poster

It's different on a per language basis, but in most languages:

Braces {} are generally for object notation and grouping.
they define an object. Such as when you use them to define a class, enum, stuct ect.
Or for enclosing a memeber or code group, such as a method or property.

In your example:

string[] Meats = { "Roast Beef", "Salami", "Turkey", "Ham", "Pastrani" };

This is an object notation. It's not short hand specifically for creating an array, you can actually create any object this way.

public class myobject
    {
      public string Title {get; set;}

      public bool isInit {get; set;}
    }

    //create shorthand:
    myobject mo = new myobject(){Title="mytitle", isInit=false};

Brackets [] are indexers
when an object can be indexed, the [] supply a selector for the index.
When decaling a type, adding [] to the end is stating that you want an indexable array.
The only other time you will see brackets in C# is for flags. Sometimes when you define a class or interface you will want to flag the members for serialiaztion such as if you wanted to ignore a property in a class you would use the [XmlIgnore()] flag.

public class myobject
    {
       [XmlIgnore()]
       public bool ShipmentSpecified
       { get; set; }
    }

Parentheses () are used in math, casting, grouping, and calling.

Mainly () are for parameters. They are used to denote a situation where a parameter could be passed or recieved. This is most …

iConqueror commented: thankyou that was very helpful +1
Diamonddrake 397 Master Poster

My email provider refused to send the attachment because of its file size, I have uploaded it to megaupload you can find it here

Diamonddrake 397 Master Poster

Ok, putting all your logic code that was in the on paint into the timer event was very simple, just a copy and paste and it worked without a fuss. still flickered with a bacground and then I found that you were invalidating the panel from the paint event (you should never do that) So i removed that call from the logic loop and now the background doesn't flicker.

the move speeds need to be modified but other than that, it does seem to work.

I'll email it to you.

Diamonddrake 397 Master Poster

I am downloading it now, I taught myself through books, trial and error, codeproject articles and from help of people here on daniweb. C# is an easy language. Programming is a challenge. I guess that's why I do it.

Diamonddrake 397 Master Poster

if you post your project, I will take a look at it. See if I can integrate it for you.

I didn't have the finances to go to school, but hopefully I will soon. I'm 23, I see the software I marketed to be a sign that I have what it takes, but there is a long way for me to go. Really I should get into games, that seems to be the future of the programming industry. That's all that really sells these days, I'm thinking of getting into programming for the android and windows phone 7. Maybe I can make some money. :)

Diamonddrake 397 Master Poster

The error is due to a namespace conflict. at the top of your class the using statements that are in place are there to limit the amount of typing you have to do. Since you have a "system.windows.forms" and a "system.threading" using declarations, in order to disambiguate you will have to use the full namespace to the timer basically you just have to use

System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();

The game will still likely be slow, just because its a GDI and winforms control based game. But it should drastically speed the game up. It would be better if you used directX or XNA but both of which would require a total rewrite and you would have a lot of learning to do before you could actually start writing reliable code.

Programming is a great hobby, but as the human condition goes, there will always be someone way better than you, no matter how good you are. And with programming, you can be a great great at one thing, and suck at another. I love programming and have enjoyed doing it for the past 3 years or so, started as a hobby, still is for the most part. I sold an automation app to a multi-international corporation that designs and manufactures stoves so technically I am a pro :) but only technically. lol

The guys to look out for here in the C# department are sknake, ddanbe, adatapost, and Ryshad many people make good contributions these are …

Diamonddrake 397 Master Poster

I see, it appears that the all your trouble stems from the fact that you are doing all your game logic in the paint event.

All your frame advance type game logic should be handled in a timer event or something, NOT the panels paint event.

every time anything moves or changes in or over the panel, the paint event gets called, and it should ONLY handle DRAWING for the panel. Since you are using pictureboxes for most of your characters and such they handles thier own redraws, thats the only reason this works at all.

create a timer timer that fires how ever many millisecons you want your frame difference to be, and on its Tick event put practically all that code that you have in the game panel's tick event. then when the game starts, be sure to start the timer and then your panel's background should be fine.

during that paint event, that's what draws the background on the panel, its sealed in the Panel class and happens before anything you added there, but it isn't update til all that's code runs. Pain events are for PAINTING! remember that and you will see a big performance increase.

More on XNA, xna is in C#, but supports 2 different drawing systems, a specialed managed directX which lets you use the client's graphics card to make the game run faster. and then a 2d drawing system that is 1000 times more efficient than using …

Diamonddrake 397 Master Poster

This is more complicated than you would think, Are you invalidating the entire control surface? or just what may have changed? are your picturebox's userdrawn with a transparent background? or just regular pictureboxes? are you drawing directly to the surface of the panel using its paint event? or are you moving controls in front of it?

The root of the problem would be that you are refreshing the entire panel. Requiring it to be redrawn. GDI+ is slow. That's why games are usually written in XNA for C# or DirectX, openGL, ect. If you are going to use GDI+ for a game, you need to make sure that you only invalidate areas that change, not entire sets of controls or the entire game surface at every update.

for example, if the top left corner 20px wide and 10px tall displays the score, then that information might need to be updated often. If that information is on its own control, then that control will handle invalidating it's self. But if that data is drawn onto the panel, then it should be manually invalidated, but you should pass the rectangle that contains the area to be invalidated to the invalidate method.

Kind of long winded, I hope you got something out of that.
for any other assistance, we will need to see some code to know what we are dealing with.

Diamonddrake 397 Master Poster

One thing about choosing the method of sending email is what will be sending the mail. Its important that if this is a mail application, and you intend to allow the end user to modify the serer settings to match their own info, or you intend to use this for personal use only. Then its fine to use this method.

But if you are creating a production application and you expect to distribute it. Yahoos not going to be happy with you sending 100,000 smtp relays on your free yahoo account, plus the messages will always be traceable back to your account, and you will be liable for that.

If you are, for example, adding a call home system in an application, to report errors, or maybe a feedback mailer. Then a good system would be to have the desktop app post some vars to a script on a webserver somewhere and have the server either handle the smtp server setup so you can change it easily and it will reflect in all the applications that use it. Or have the webserver its self handle the SMTP. all asp.net web servers have smtp built in. They always suggest you don't use it, and VS will give you warnings that its depreciated. But it works, if you just use System.Web.Mail.SmtpMail.Send(message) on a asp.net site. It will just send it. No questions asked. Then you can set a response and have your desktop app check for …

Diamonddrake 397 Master Poster

If the items in the list box get hightlight when you hit the keys this sounds like that form isn't getting your keydowns, but the listbox is because its focused. In the designer, click on the form's title bar to select it, then in the property inspector set the form's "KeyPreview" property to true. This will make the parent form get the key event instead of just the selected control in this case the listbox.

That should do it.

jonsca commented: Nice one +6
Diamonddrake 397 Master Poster

sometimes there is a separate process, service, or pool of processes that serve no other purpose but to make sure that no matter a certain process is still running. this is often called a babysitter process. Many many viruses have them. So when you kill it, it starts again.

So long as you identify your bad processes well, then I imagine it can't be any more harmful than the virus itsself.

you still want to throw some thread.sleeps in the loop to slow done the repeat rate.

best of luck.

Diamonddrake 397 Master Poster

The reason your loop eats up the proc is because you are running an infinite loop with While(true) you should be using some kind of reachable goal While(somevalue == true) that way you can break the loop by reaching a goal. If you throw a Thread.Sleep(500) in the loop, you will allow the loop to sleep, easing the usage of the proc and letting the OS prioritize another process for CPU usage.

the cancellation is a little different. you have to put a if statement in the loop, on every itteration you should check the CancelationPending property of the background worker. this will tell you if backgroundworker.CancelAsync has been called.

http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx

It's a fairly simple process.

BTW. its not the best idea to be constantly looping and killing processes. You can put the system in a bad place, especially if the process you are killing has a babysitter or crash protection service attached to it.

Diamonddrake 397 Master Poster

at the end of the this thread page, underneath my post and above the text box where you type your reply is a an area with purple and gray text, asking if you want to mark the thread as solved. just click the link that's in the middle of if.

Diamonddrake 397 Master Poster

There is also a beforeLabelEdit event. Can't think of anything I would use that for. Don't forget to mark the thread as solved.

Diamonddrake 397 Master Poster

The Listview control has an event called "AfterLabelEdit" This event will fire after you change the text with beginedit. it will fire this event and you can validate/update the changes then

Diamonddrake 397 Master Poster

Typically a thread in a forum handles only one question. I can see how this might not be worth branching out a new thread. But I think you have hand more than enough help from the community to mark this thread as solved regardless if you have worked all the bugs out of your program.

Diamonddrake 397 Master Poster

you could mark this thread as solved using the mark as solved link above the quick reply box. That way I actually get credit for helping you.

Diamonddrake 397 Master Poster

Ok, the only problem was that you created the myObject class as an internal class of one of your forms. This made it not available to all the other classes in the application. I simple cut it and pasted it into a new class file, in the root of the namespace and it compiles fine.

Diamonddrake 397 Master Poster

why don't you just upload the code to daniweb, click advanced editor and click manage attachements. anyway, I'll haev a look

Diamonddrake 397 Master Poster

At the top of the class file that contains the XMLSaver there should be using directives for the serialization of xml using System.Xml.Serialization; but if you just copied the entire file, then the namespace declaration just below that probably still has the old project namespace.

just change namespace WinFormsApplicatin1.Utilities //or whatever it is

to namespace Utilities should work then

Diamonddrake 397 Master Poster

did you make sure to create a myObject class in your other project.

They are based on a class that represents the myObject object. It is defined at the end of the main forms .cs file

Diamonddrake 397 Master Poster

OK, This is definitely homework. No doubt about it. If you are really serious about programming then something this simple should really be figured out on your own through research on the web.

if you studied the XML classes in the .net framework you wouldn't have any problem with this. But personally I feel that manually creating a xml document is ridiculous. So I use XML serialization.

After all the help that the rest of the community here as provided, you should have been able to at lest hack up something that worked. But i have edited your project making minimal changes as possible, commenting all the changes, but still making the application work well. hopefully you will read through it and take the time to understand all the changes that I made. With programming there is NEVER only one way to do something. 100 programmers are likely to come up with 150 different ways to do the same thing.

If you have any questions about how or why just post back.

Diamonddrake 397 Master Poster

I think its the concept your are struggling with, its just as important to know how code works, as it is to know how to use it. Before you jump into something complicated it helps to write some pseudo code showing the steps involved in a process before you ever write any real code.

Also, for small controls, like a textbox, its fine to use the control to store the data like a string. and not save it anywhere else. But when you are working with a good amount of data that you need to manipulate. It helps to create a List of objects and just use the listview control to display that data. not keep track of it.

basic pseudo:
onLoad
- Create a List<myObject> to hold your working data.
- check for a saved file, and populate that List with data from it.
- populate a listview with the data from your List.

onItemAdded
- add the item to the List.
- add the item to the listview.

onClose
- save the List to a file

It's a good practice to write support methods, like a method that takes an List<t> and populate a listview the way you like it. and of course methods that load and save the data, like earlier ones in this thread. I personally like XMLSerialization, but plain text is faster. Its just more complicated and it doesn't save your data as …

Diamonddrake 397 Master Poster

Its more likely that you have an assembly loaded that relies on the older version of that dll. Don't forget that your project references are important, but many dlls make references of their own that you don't see.

Diamonddrake 397 Master Poster

the substring is an instance method of type string that takes an indexed start int and returns that character in the string to the end.

so, if string line = "size=2699309";
then line.SubString(5) would count to the index of 5 or the the 6th character in the string and return that character til the end of the string.

s(0)i(1)z(2)e(3)=(4)2(5)699309

since the 2 in 2699309 is in the Index position of 5. the 2 til the end of the string is return as a new string 2699309

MasterGberry commented: Perfect explanation +1
Diamonddrake 397 Master Poster

If app A is not running prior to clicking the button in app B, then simply create a command line argument that is of type int, and set up the app to check for it, and select the menu item based on that command line argument.

Then in app B, instead of just using

System.Diagnostics.Process.Start("A.exe");

instead use something like

public void startAwithMenu(int menuNumber)
        {
            System.Diagnostics.Process appA = new Process();
            appA.StartInfo.FileName = "A.exe";
            appA.StartInfo.Arguments = menuNumber.ToString();
            appA.Start();
        }
Diamonddrake 397 Master Poster

I am not familiar with that console app, but passing arguments is as simple as.

CurrentProcess.StartInfo.Arguments =  @"-ip 192.168.1.1";
Diamonddrake 397 Master Poster

If you look closely. Console1 is a custom control that derives from textbox. The redirect standard output needs a stream. The Console class redirects text from the stream to a textbox, and vise versa. The console control code from that project is as follows.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace RedirectStandardOutput
{
    public class Console : TextBox
    {
        public Console()
            : base()
        {
            this.Multiline = true;
            this.KeyPress += new KeyPressEventHandler(Console_KeyPress);

            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }

        private void Console_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (InputStream != null)
            {
                if ((int)e.KeyChar == 13)
                {
                    InputStream.WriteLine();
                }
                else
                {
                    InputStream.Write(e.KeyChar);
                }
                InputStream.Flush();
            }
        }

        public void Start()
        {
            this.Text = string.Empty;
            if (OutputStream != null)
            {
                MethodInvoker readOutputStream = new MethodInvoker(ReadOutput);
                readOutputStream.BeginInvoke(null, null);
            }
        }

        public void ReadOutput()
        {
            int value;
            while ((value = OutputStream.Read()) != -1)
            {
                Invoke((MethodInvoker)delegate
                {
                    this.Text += (char)value;
                });
            }
        }

        public StreamWriter InputStream
        {
            get;
            set;
        }

        public StreamReader OutputStream
        {
            get;
            set;
        }
    }
}

That is your problem. you are trying to use use a standard textbox to eat the stream, And that is not quite how it works.

Diamonddrake 397 Master Poster

I argue that, no its not the only way. There is NEVER an "only way". As a programmer, finding ways to get around limitations is only the first step of reaching a goal.

But first, why do you need to change the font color and properties to show a selection? is not highlighting the selection with the select method not enough? I don't know why it wouldn't be.

But if you do want to change the font, and you are set on it. Then you have some key choices. You can implement your own stack and custom undo, which isn't that hard at all, just google it. its out there in a million places. Or you can custom draw your rich text box like it typically done for spell correction here is a link to how to do that Owner Drawing a Text Box. But those are only 2 of what could be a hundred possible solutions. you could even inherit from the rich text box and override some methods and add the begin and end change events, or decompile the code and add them and recompile it in your solution.

There is always a way. Here is 4 to try. Good luck and happy coding!

Diamonddrake 397 Master Poster

Before you spend 200 bucks, just try and create your own. See what happens. GDI+ is not all that complicated, just draw and fill a few gradient rounded rectangles. Even still, first be sure your app benefits from a ribbon type interface.

Diamonddrake 397 Master Poster

WPF uses a different drawing system, so it works better for flashy/fancy interfaces, But winforms isn't going away. Ribbon interfaces isn't really anything complicated. Its just a custom drawn tab bar with custom drawn buttons. If you just user draw the standard controls using images. Throw a tab control with a few buttons and pages and you're practically half way done. As a programmer you get all caught up in how you do things, but when a normal PC user runs your program they don't care if you used GDI or WPF or just lined up some images. All that matters is that it looks ok, it works, and its familiar.

Personally I do not like ribbon interfaces, on today's wide-screen monitors and the standard portrait style document the last thing I want is something to make the viewable document have less real estate.

In the beginning users knew, menus were on top. soon people wanted access to their favorite menu items, so then came tool bars, then someone said, tool bars would be awesome with tabs, so then came the ribbon with huge buttons and tabs. Every program doesn't need to look like MS Office.

A good place to start is with the code that's already out there for drawing on the form's non client area, then just going from there. And if you want some good pop up control code I have a good article about it on codeproject just search articles from user DiamondDrake.

Diamonddrake 397 Master Poster

Here it is
This is a fully working free example.

Diamonddrake 397 Master Poster

I personally never got into WPF, I like my old winform applications.

in C# you can't do true gradient transparency but you can achieve that look a multitude of ways. If you set the formborderstyle to none and set an image as a background you can use a color key to make a single color transparent like any gif image on the web does. to bring that further to light you can layer your form and add true full 255 levels of transparency but that requires 2 forms one for the border and another for the use-able part of the form. Looks great but gets complicated, then the last honorable option would be to capture the desktop and draw it on any transparent areas and use that as the form's background.

Anyway, once you get your borders looking how you want you just create custom buttons that have the desired effect for the Minimize/maximize/close.

Anyway, Attached is an example of using an image with a transparency key, custom image rollover buttons for shell, with all the code there, even for moving the form. I was working on this for an article that I never got around to working on. I'm sure its right up your alley. It even includes the photoshop psd files of the images i created.

i hope it servers you well.

nssltd commented: Thanks just what i needed plus i like the minature shell design you added in on the project its so simple yet so effective :D +1
Diamonddrake 397 Master Poster

Instead of creating the file separate, you could just add an empty database as a resource into either your exe or a dll and have a method that extracts the stream to the new location. The user will have no idea that your program isn't creating the file from scratch, it won't rely on any apis and its only a couple lines of code.

Diamonddrake 397 Master Poster

that's the alt text for the image. If the image failed to load that text would be there instead. Its your browser that's showing that pop up. not the site. But I agree it is annoying.

Diamonddrake 397 Master Poster

... come on guy you're bouncing all around it. The reason you code didn't' work is because you created a new panel but didn't add it to the form's control collection.

The button is IRRELEVANT. you can assign the points and refresh the panel at any event. on load, on button, on mouse down. doesn't matter.

I have included an example project of a finished working solution. It could be adapted to work more toward your purpose. But this is a proof of concept.

Diamonddrake 397 Master Poster

You are still creating a graphics object. Don't do that. use the paint events args graphics object.

e.Graphics.DrawLine(.....);

and after your button click refresh the panel.

[I]panelname[/I].Invalidate(false);

Also start with a standard Panel control. get simple working before you move to complicated.

Diamonddrake 397 Master Poster

You'll need to throw a contol, like a panel, in the area you want the arrow to be drawn in. Then hook up its paint event. Then use the event's painteventargs object to access the panel's graphics object. and use the graphic's objects drawline method to draw from point to point. Drawing curves are a little more complicated as then you need to draw Arcs and they take a complicated set of params to achieve a desired effect. But all the documentation is there. its just about making it happen.

Diamonddrake 397 Master Poster

first off, if you have visualstudio 2008 installed then you have .net framework 3.5 installed. They come together in the installer. you can't have one without the other.

and assuming you mean a StatusStrip control. You just set its BackgroundImage property to your image. you can't set a text property to an image as that is a string type. C# is strictly typed. You could also add a button or label to the statusstrip and use the button or label's background image, or image properties.

Diamonddrake 397 Master Poster

you can't embed the .net setup. but you can freely share the .net redistributable. But don't worry. if you use visual studio to create a .msi installer package, it will automatically make sure you have the required .net version installed and if not, it will prompt to install it from Microsoft.

Diamonddrake 397 Master Poster

C# is a class based language, EVERYTHING is in a class. So the ideology here is correct. but you are forgetting that the name "form1" is a reference variable of type "System.Windows.Forms.Form" you can't use a variable if you don't have a reference to it. So what you need to do is pass a reference to one form to the next. you could do that through a property, or constructors, or whatever you feel.

Diamonddrake 397 Master Poster

when you draw using the form's on paint method you are drawing directly to the form. any controls you create and add to the form are on top of the form. so if you draw on the form, the controls will ALWAYS be on top of your drawings.

you can't just draw a circle on top of multiple controls. If you need complicated drawing consider not using controls, but instead using rectangles and manually drawing all the needed elements of the composite.

Diamonddrake 397 Master Poster

It could possibly be the .net version you have installed on the XP machine. but you might try using the another method that uses reflection.

just replace this line

StartPath = Application.StartupPath;

with this one

StartPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

if it doesn't work on xp after that. It might be the .net version or a problem with your laptop. its all good code.

Diamonddrake 397 Master Poster

OK. you need to create a Class variable that is of string type. I will edit this source and post it back. there is no need to "reset" the startuppath.

using System.IO;
using System.Data;
// importing the OLEDB thing :P
using System.Data.OleDb;
using System.Windows.Forms;

namespace Login_Form
{
    public partial class frmAddMobile : Form
    {
        public frmAddMobile()
        {
            InitializeComponent();
			
			//Set start up path here.
			StartPath = Application.StartupPath;
        }

        // Global Areas Stuff - U Knw :D :D bt dnt ask me haridhaa :D ------------------------------------------------------

        // Global vars - new
        OleDbConnection dbcon;
        OleDbCommand com;
        string sql;
		
		//create string here in class to hold startuppath.
		string StartPath = "":

        // Creating the Onload event
        private void frmAddMobile_Load(object sender, EventArgs e)
        {
			//use startpath string instead of Application.StartupPath;
            string dbloc = StartPath + "\\G2.mdb";
            dbcon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+dbloc);
        }

        // Method Used to Clear The Text Fields
        private void FormClear()
        {
        }

        // Button & Combo Box Coding Stuff -----------------------------------------------------------------------


        private bool checkid(string id)
        {
           // i removed this code to make code look smaller ;)
        }

        private void btnSend_Click(object sender, EventArgs e)
        {

            if (txtMid.Text == "")

                // i removed if statements to make the coding bit smaller

            else
            {
               
                string mid, mmno, mprice, minfo, manu;
                DateTime doa;

                mid = txtMid.Text;
                mmno = txtModelNo.Text;
                mprice = txtPrice.Text;
                minfo = txtInfo.Text;
                manu = cmbManu.Text;
                doa = DateTime.Now;

                bool id = checkid(mid);

                if (id == false)
                {
			// removed if to make code look smaller ;)
                }

                if (txtPath.Text != "")
                {
                    FileInfo …
Diamonddrake 397 Master Poster

i don't think you followed me, if Application.StartupPath gives you the dir you need the first time you call it. Then you can save that path to a string. and then from then on out use that string instead of the Application.StartupPath.

The reason why it "changes" is because the working directory changes when you change it in a open or save file dialog box. But that doesn't matter because when the program first run you saved that data to a variable that WON'T change unless you manually change it.

its a class variable, available to the entire form.

If it didn't work, post the code that doesn't work. I will tell you why.

Diamonddrake 397 Master Poster

Welcome to the forum!
You have a couple options here. You can use reflection to get the executing path of the assembly. Or since you are new at it. I would just save that startup path to a string class variable. they use that from then on out. best place to do that is in the constructor.

public class Form1 : Form
 {
     private string StartPath = "";

     public Form1()
     {
       StartPath = Application.StartupPath;
     }

     ...
  }

Then just use that variable instead.

Diamonddrake 397 Master Poster

I think your best bet here is to make your app run in the background with a system tray Icon. Using a timer and on its tick, subtract the time you started from the current time. then compare that a timespan.

attached is an example app project. I figured I'd need this for something eventually so I went ahead and hacked up and example.

Diamonddrake 397 Master Poster

Yeah, I tested it. It works fine. just don't put .exe on the process name.

IsProcessOpen("notepad");

another note. you might want to disable the update timer before you call the message box. otherwise you are going to end up with 10 message boxes before you get a chance to click ok.

Diamonddrake 397 Master Poster

first. 100 ms is way to frequent. you could save some processor usage by slowing that down to 1200ms.

2nd IsProcessOpen("notepad.exe"); according the comment in your IsProcessOpen method, it says not to use the ".exe" but instead use just "notepad"

//Be sure to not
//add the .exe to the name you provide, i.e: NOTEPAD,
//not NOTEPAD.EXE or false is always returned even if
//notepad is running.

Also you don't seem to do anything with the information after you find it.

Diamonddrake 397 Master Poster

*sigh*

string path =  Application.StartupPath;
string subfolder = @"\Images\";
string imagefilename = "myjpeg.jpg";

pictureBox.Image = Image.FromFile(path + subfolder + imagefilename);