Diamonddrake 397 Master Poster

Passing data between forms is probably the first noob question asked here, search the forum you will literally find HUNDREDS of posts about it, google it you will find Dozens of answers. Typically done with properties. you could also use a class with static members, or even pass data through the ctor. Its a very simple problem. here are a handful of suggestions.

http://www.vcskicks.com/data-between-forms.php

http://www.codeproject.com/KB/cs/pass_data_between_forms.aspx

http://msdn.microsoft.com/en-us/library/ms171925%28VS.80%29.aspx

http://www.c-sharpcorner.com/UploadFile/DipalChoksi/PassingDataBetweenaWindowsFormandDialogBoxes11242005035025AM/PassingDataBetweenaWindowsFormandDialogBoxes.aspx

http://www.c-sharpcorner.com/UploadFile/alindag/HowToPassValuesBetweenWindowsForms.htm02242006061520AM/HowToPassValuesBetweenWindowsForms.htm.aspx

http://www.youngcoders.com/net-programming/29915-how-pass-data-between-two-forms-c.html

http://www.dreamincode.net/forums/showtopic75208.htm

Not to be rude, but I don't understand when programmers can't get around this. Its a very simple problem, there is tons of material out there about it. I would use it as a bench march. If you can't pass your data between forms after 45 minutes of trying, Programming probably isn't for you.

Diamonddrake 397 Master Poster

Firstly, you are not specifying a path for your text file, just a file name, this is bad and can lead to an error. you should always specify a full path.

this write the data to a text file, then loads it back and uses its contents to fill the listview, if this code update the listview then you ARE saving it to the file.

You need to separate this, on form close loop through the listview items and write them to a file. on form load loop through the text file and load it to the listview.

but there is a more OOP way to go about it. Create an object that represents a contact, with 3 strings name, number, and address, as a property. Then create a list of those objects and use that as a source for your listview and serialize it to a XML file on save, deserialize it on open.

Diamonddrake 397 Master Poster

Try irrKlang sounds engine, its free for non-commercial apps. and fairly cheep for commercial ones. It does wonders and I have used it with doublebuffering plenty of times.

I'm think your problem might have to do with the system you are using or maybe some other part of the code as a asych call the the windows sound api shouldn't block your thread regardless.

but irrklang should work.

Diamonddrake 397 Master Poster

There seems to be an error, you use filearray like a string when it should be used as an array. and your for loop does the same thing over and over again, it should be

string[] fileArray = Directory.GetFiles(sourcePath);
            string fileName = null;
            for (int i = 0; i < fileArray.Length; i++)
            {
                fileName = Path.GetFileName(fileArray[i]);
                File.Copy(fileArray[i], destinationPath + "\\" + destinationFolder + "\\" + fileName, true);
            }

even then you are creating and assigning an unnecessary variable. should simply be.

string[] fileArray = Directory.GetFiles(sourcePath);
            for (int i = 0; i < fileArray.Length; i++)
            {
                File.Copy(fileArray[i], destinationPath + "\\" + destinationFolder + "\\" + Path.GetFileName(fileArray[i]), true);
            }

Furthermore, another way would be to use the FileInfo class for copying files. Regardless, Thanks for sharing.

Diamonddrake 397 Master Poster

if you just need to play 1 sound at a time try http://www.daniweb.com/code/snippet253704.html

i posted this snippet a while back, its async and works great, but if you play another sound it will stop the first sound. so just one sound at a time.

Diamonddrake 397 Master Poster

using the async load of the picturebox will work to an extent but eventually you will have loaded a ton of full size pictures into memory unnecessarily slowing down the system. alternatively you should consider creating a control from scratch that asynchronously reads the images from disk and creates a new image in the size you need and save it in a variable and on paint draw it to the surface of the control.

as for the threading the load, a thread pool would be the most efficient on a multiprocessor system, but otherwise a single worker thread should do fine. having the worker thread load the images, resize them, create the control, add the image to it and the pass that control object to the gui thread to be added to a container.

Diamonddrake 397 Master Poster

But you didn't' mark the thread as solved and you did so by editing your original post. That doesn't make any sense. But ok.

Diamonddrake 397 Master Poster

I don't understand the question... Come again?

Diamonddrake 397 Master Poster

Icons for menu strips are 16px X 16px, and this is the default size for the Imagelist control.

Standard application icons contain 16x16, 32x32, 48x48 and in Vista and Win 7 they added 256x256.

Tool bar icons are also typically 16x16 But the developer has complete control over that decision. You can create Icons in any size you see fit and use them in your applications. 24x24 is a popular toolbar icon size based on that decision. But as monitors get larger, and screen resolutions get larger, icons will continue to get larger as well to compensate.

Diamonddrake 397 Master Poster

why do you need names for your columns? why not just place the value in the table and have an auto increment id?

Diamonddrake 397 Master Poster

I included a zip of the classes I decompiled from System.windows.forms that is used by the combobox. I couldn't find a definite answer to what was responsible for drawing the focus rectangle but it appeared that it send a windows message to the system and windows draws it. I couldn't be sure without testing though.

Diamonddrake 397 Master Poster

Processors these days perform 4 instruction sets for ever tick of the crystal oscillator from the system clock. If anything its not the processor. I would say its a limitation on the .net virtual machine sand boxing all the code it executes. If the OP seriously need accuracy at less than 1ms he either needs to switch to a native language or more realistically create a dedicated circuit in the device that uses a timing crystal of its own.

Just my 2 cents, best of luck with your project.

Diamonddrake 397 Master Poster

You didn't include the code for the FilgraphManagerClass so that makes it hard to determine a solution.

But since you are just playing the video and not trying to do anything else with it I would consider using managed directx audiovideoplayback library. It has a video object that is very simple to use with play(), pause(), rewind(), length, currentposition, and other helpful methods and properties. this uses Direct X to wrap direct show(that builds a filter graph similar to quartz.dll) where it appears that the filtergraphmanager class does a similar thing.

Diamonddrake 397 Master Poster

It's not that it's an event, it is that it is a delegate. A delegate is a pointer to other methods. A delegate can point to an unlimited amount of methods and when you call a delegate you call all its appointed methods.

Its used so at compile time the method doesn't need yet to know which methods need to be invoked. and is assigned always via a "+=" operator.

Diamonddrake 397 Master Poster

There is a problem with this, very seldom will there be only 1 pixel of a particular color anywhere, It is very l likely that you will get hundreds of coordinates with even an unpopular color as many images contain millions of colors to make up and image.

but I digress a good approach would be to capture the entire screen as a bitmap (assuming you want screen coordinates) and then loop through that bitmap using getpixel and compare its color to your color, and then add that coordinate to your List of coordinates.

if you just wanted to look in a particular window, you can still screen cap the whole screen but just loop through a rectangle that is bound to that windows position on screen.


although, I can't see the use for this. Best of luck.

Diamonddrake 397 Master Poster

1000 ms is 1 sec. so divide by 1000 you get seconds, divide seconds by 60 you get minutes, the remainder is left over seconds. So if you were interested in doing the math on the fly you could go

//assuming Milliseconds is a var holding the current value in milliseconds to be converted.
string Hours = Milliseconds / (1000*60*60)
string Minutes = (Milliseconds % (1000*60*60)) / (1000*60)
string Seconds = ((Milliseconds % (1000*60*60)) % (1000*60)) / 1000

or you could use the TimeSpan class as follows

TimeSpan t = TimeSpan.FromSeconds(80);
string Position = t.ToString();

Now please do some research before you ask simple questjions like this. It will stick with you longer and you will grow faster as a programmer if you take the time to learn how to solve a problems on your own.

The forum is best used to get you un stuck when you have been stuck or my personal favorite, for discussions, as I love to know how someone else would have done it.

Diamonddrake 397 Master Poster

an easier way it to use the Microsoft.directX.audiovideoplayback.audio class It provides a current position property and a length property that makes it very easy.

Diamonddrake 397 Master Poster

Thanks, I keep getting distracted using it when i should be working on it.

Hopefully I will get some help here but I might just go the route of having it auto detect the pads I can get the info on and then for all other game controllers have a configuration to let the user's set up which button goes where.

And of course, when i finish the app I will post a link here. People are gonging to want to try this, I can't get enough of it.

Diamonddrake 397 Master Poster

I have written a Rockband Drum kit app that lets you use the Rockband Drum kit with your PC as a drum synthesizer. It has 30 Drum wav sounds and can also be used to play sound through MIDI as well, working on MIDI recording and a loopback driver to use it as a MIDI input but all that aside.

I only have access to the Playstation2/3 Rockband drum kit. I don't want to go the route of having the user's set up the button mapping. I have it automapped for my Drum Kit, but I need to know the "title" of each controller and the button index of each pad.

EX: my Rockband ps2/3 controler specs are
title: Harmonix Drum Kit for PlayStation(R)3
red pad is 2, yellow 3, blue 0, green 1, ect. ect.

what I need?
I need that info for the RockBand drum kit for Xbox360 and wii, the Guitar hero drum kit for xBox360 and wii and also any 3rd party drum kits for any of the systems so I can integrate them as well.

Thanks, the app is working great so far even has graphical representation of the pads on screen that flash when they are struck. I have written A LOT of apps, but this is the first one that I am really going to take all the way to the end.

Diamonddrake 397 Master Poster

Ok, A "Form" is that familiar window of the application that has the close button in the corner, windows communicates with a program via a message system where it sends codes to all apps as numbers, these numbers tell the form that things are happening. for example, a key is pressed, the mouse has entered the form, the form has moved, or a usb device has been plugged in. when you create a hotkey you tell windows that you want a message to be sent to your program when that key is pressed, simple enough.

a thread can be considered a "task". a thread is created when your program runs. This thread is a single concurrent run through the code that always follows in line. A program runs in a loop processing the windows messages and checking each event to see if it has fired. if during a method your "sleep" the thread. you tell the thread to do nothing for a period of time. in which it will not process events or windows messages. So when you sleep the thread you stop your hot key from getting processed. but windows does send it to your app, but your app misses it.

If you create a second thread (probably using the Background worker control would be easiest) and perform your work there, it should solve everything.

Diamonddrake 397 Master Poster

hrm, not sure how much more help I could be here, sorry.

Diamonddrake 397 Master Poster

if you are sleeping the thread it WILL NOT process messages so the hot key will not work during a sleep.

you could put that work method into a separate thread and it should work find then.

Diamonddrake 397 Master Poster

I created a new project and pasted this code in, tied up the load and closing events and it works just fine.

so here is the possibilities.
1) you have a code loop going that keeps your form from processing windows messages, using a separate thread or calling Application.DoEvents(); could fix that.

2) Another program on your system is suppressing the Q key. Not likely but entirely possible. simple solution there is to just try another hotkey. just plain "Q" is a bad hotkey, what if you had to type a few words? a better choice would be like F9

3)IDK, but certainly other possible problems. HotKeys are very simple though, I have never had trouble with them. I have written a slew of little apps that run all the time hidden and show them selves on a hotkey press. (my personal favorite is alt + an arrow key)

Diamonddrake 397 Master Poster

I'm not sure what method you are using to "zoom" your picture box. But I think you might want to find another method.

Diamonddrake 397 Master Poster

The hot key should work at any time regardless of selected window. Please post your code and I will help you.

Diamonddrake 397 Master Poster

This is very unclear, A better explanation would help to get a better answer but to resize a control you just set its width, and height via those properties

//example
pictureBox1.Width = 200;
pictureBox1.Height = 200;
Diamonddrake 397 Master Poster

commandexecuted is route -p delete 0.0.0.0 mask 0.0.0.0
I am expecting currentstatus = ok, but got M

Not sure what you mean here.

Diamonddrake 397 Master Poster

#
if (ctrControl.Controls.Count > 0)
#
{
#
//Call itself to get all other controls in other containers
#
ClearForm(ctrControl);
#
}

That's clever. Gets all the child controls.

Diamonddrake 397 Master Poster

In vista and win 7 so long as User Account Control is turned on you will be prompted, a much better approach would be to check if the current app is running as an admin and if not request that it is, then restart it, then check again, that way the program won't get any further until they user accepts making it run as admin.

Then just remember that any program started by a program with administrative privileges will have administrative privileges.

Here is the simplest way, the ultimate solution.

first add these namespaces

using Microsoft.Win32;
using System.Security.Principal;

then to the onload event of the first form add this

WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator);

            if (hasAdministrativeRight)
            {

            }
            else
            {
                if (MessageBox.Show("This application requires admin privilages.\nClick Ok to elevate or Cancel to exit.", "Elevate?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    ProcessStartInfo processInfo = new ProcessStartInfo();
                    processInfo.Verb = "runas";
                    processInfo.FileName = Application.ExecutablePath;
                    try
                    {
                        Process.Start(processInfo);
                    }
                    catch (Win32Exception ex)
                    {
                        Application.Exit();
                    }

                    Application.Exit();

                }
                else
                {
                    Application.Exit();
                }
            }

The key here is the "runas" verb. this tells the system you want to run the current application as admin.

Now, assuming you just want to run a single child app as admin you just use a startinfo object using the verb "runas"

example as follows

ProcessStartInfo startInfo = new ProcessStartInfo()
            startInfo.FileName = @"pathgoeshere";
            startInfo.Verb = "runas";
            startInfo.Arguments = "anyargshere"; //feel free to lose this line

            Process p = new Process(); …
sknake commented: excellent +6
Diamonddrake 397 Master Poster

found a temporary solution My snippet But i think i may use irrKlang sound engine. i found that you can play sounds from memory using its Sound object interface.

Still undecided, but i did find enough information to feed my needs.

Diamonddrake 397 Master Poster

I needed a way to buffer into memory an entire wav sound file to be played back a moments notice, as if for a game. So i created this class, simple instantiate it by passing to it a string and a bool indicating if you should buffer it to memory. after that you just call its play method whenever you need it and the windows api automatically handles async playback.

Sadly, It works just shy of how well I need it to for my purpose. but it does work very well. I'm not very good with clean up code, I believe everything here should garbage collect nicely, but if anyone has any input on that I would appreciate it.

Diamonddrake 397 Master Poster

google books would only let me read some pages, I am actually more concerned with ways to play sounds vs manage memory. Although it did look interesting.

Diamonddrake 397 Master Poster

Interesting facts, If you have ever programed a console game, the entire idea is to create a game loop, that repeats until the game win conditions are met.

but i would say if you disable the buttons that affect your loop, doEvents shouldn't cause a problem. Microsofts documentations actually show how to use this method by using it in a load file loop. http://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx

Some Q and A from Microsoft:

Q: Why is DoEvents in the BCL namespace?

A: Glenn (Microsoft) Threading is difficult, and should be avoided if there's an easier way. If all you need to do is yield on your UI thread, DoEvents is perfect.

Q: DoEvents is evil?

A: Glenn (Microsoft) Yielding on the UI thread is a legitimate Windows programming practice. It always has been. DoEvents makes it easy, because the situations in which you need to use it are simple.

The biggest problem with doevents is it leaves the possibility to re-enable your current loop via the interface, but you can simply disable the button while the loop is in place.

Threading is hard, using a background worker can be simple. But its wrapping something so much more complicated and dangerous to you application.

Quote from codinghorror.com:

"You've never truly debugged an app until you've struggled with an obscure threading issue. Threading is a manly approach for tough guys, and it will put hair on your chest-- but you may not have …

ddanbe commented: Nice! +6
Diamonddrake 397 Master Poster

well, you could create your own custom drawn group box control, that will take a screenshot of the full opacity groupbox and then set all of its childcontrols visibility properties to false, and draw the image of its full state in a loop of degrading opacities til it is blank, and then do the reverse for a fade in.

but that would be a lot of work, I love some attractive looking controls, I have spent a LOT of time doing silly effects like this. just remember to not go to overboard with the fancy interface that it doesn't degrade the applications real purpose.

Like all those video reformatting applications with HUGE animated toolbar Icons, or giant start buttons you can't find because they look so different than all the other buttons.

Diamonddrake 397 Master Poster

Just because I was bored one day I looked on the net for an app that would let me use my RockBand ps3 drum kit on the PC. There was a fancy direct X app out that turned out to be very buggy, slow, and annoying to use.

I set out to write my own and within 40 minutes I had a simple working system. But I ran into a problem with sound quality and speed. I need to be able to load the sound clips into memory, so not to read the files from the disk a million times. But then be able to play the sounds whenever I need them Asynchronously, and be able to play the same sound overlapping its self.

i tried using winmm.dll, and the soundplayer, and even Irklang sound engine. Irklang worked great except it only plays from a filepath, not memory, so i ran performance issues. serious ones. the other methods, although I can play from memory, don't allow the Asynchronously rapid play behavior I need.

This isn't a "serious" project. Just something i want to do. Any help with this would be appreciated. Sound is a new frontier in programming for me. Never been there and don't know what supplies I should bring with me.

Diamonddrake 397 Master Poster

kinda lost me there sknake. I don't see the harm in processing windows messages during a simple read file loop. But regardless. loading the file in a separate thread would probably be the best solution.

Diamonddrake 397 Master Poster

post your code, I will help you.

Diamonddrake 397 Master Poster

if your file is large, you might think about threading it.
or, if you load the file in a loop, then just add Application.DoEvents(); in the loop.

Diamonddrake 397 Master Poster

when you use taskmanager to "kill" the appliction, it doesn't fire any events, It simply stops the execution, This is how you close an application that has frozen. if you waited for it to handle any events, then it would still be frozen.

as for when you restart the computer or shutdown, the event will be called only if there is enough time, they system tells all applications it is shutting down and only gives them a short amount of time to handle business before it kills them. Windows 7 will show a dialog telling you which applications are still busy and ask you if you want to kill them and shutdown, or cancel. But as for XP, it just kills them after X amount of seconds.

Diamonddrake 397 Master Poster

if all you need is 1 key, then a simple hotkey would serve very nicely.

First Import the native methods you need.

//API Imports
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool RegisterHotKey(
            IntPtr hWnd, // handle to window    
            int id, // hot key identifier    
            KeyModifiers fsModifiers, // key-modifier options    
            Keys vk    // virtual-key code    
            );

        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool UnregisterHotKey(
            IntPtr hWnd, // handle to window    
            int id      // hot key identifier    
            );

Create a enum to easily understand what key modifiers are used and a constant to hold the ID of the hotkey.

//const int HOTKEY_ID = 31197;    //any number to be used as an id within this app
        const int WM_HOTKEY = 0x0312;

        public enum KeyModifiers        //enum to call 3rd parameter of RegisterHotKey easily
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            Windows = 8
        }

so we just create the hotkey bind on load, or whatever you need.

RegisterHotKey(this.Handle, HID, KeyModifiers.None, Keys.F11)

note, the hotkey ID is just just used to unregister the hot key

UnregisterHotKey(this.Handle, HID);

now we just check the WndProc to listen for our hotkey call!

const int WM_HOTKEY = 0x0312;//windows hotkey constant
        protected override void WndProc(ref Message message)
        {
           if (message.Msg == WM_HOTKEY)
            {
                   //there is your event, do whatever you like here.
            }
            base.WndProc(ref message);
        }

This is a simple hotkey, That's it, nothing else, nothing complicated. Now, you can make it complicated, if you wished. …

Diamonddrake 397 Master Poster

I do actually prefer the form method, as its easier to reuse the code and can be handled quite nicely, for example using a Alpha blended layered window call to create a beautiful help balloon with transparency and rounded edges, or even a arrow pointing to a problem setting.

a form or even a application doesn't need input focus to get mouse events, as they happen regardless of focus. (keys are an entirely different story) But as long as your pop-up form isn't in front of your control that invokes it, then it should work fine.

It is entirely possible to create a class that accepts a control and a string as params, and when called will draw the string to an image, use the image to create an alpha blended layered window, then get the position from the control and show on screen, automatically getting the mouse out event for the control and hiding after X amount of seconds of roll out, even using EX_Animate_window to fade out the image form.

but to each their own, one thing I have always believed, and that is if your program does what you originally intended it to do, then you did it right, no matter how you did it.

Best of luck.

Diamonddrake 397 Master Poster

Shouldn't be anything more complicated than

Form1 F = new Form1();
            F.Show();
            F.SetDesktopLocation(Cursor.Position.X, Cursor.Position.Y);

if you use Control.MousePosition you will have to convert pointtoscreen.

ddanbe commented: Good explanation! +6
Diamonddrake 397 Master Poster

public variables are not thread safe, the get and set properties make sure that a variable isn't in use by locking it temporarily an if is locked, causing a pause to occur until it is free. Its just the preferred way the framework handles variable access. with a simple bool value its easiest to do a Pubic Bool varname {get; set;} nothing complicated and it makes the system happy.

but if you want to use public variables that's up to you. Its obviously acceptable by the compiler, the code will run. in other languages every object is accessible from any other and there is no Public-Private mumbo jumbo.

Diamonddrake 397 Master Poster

Just add a trackbar with a min of 1 and a max of 4 then add a event handler for onchanged and update a label by dividing its max value by its current value you will get a percentage as a decimal, then multiply by 100 and add a % sign.

label1.Text = ((trackBar.Value / trackBar.Maximum) * 100) + "%";

if the slider was at 2, with a max of 4 then 2/4 = .5 and .5 X 100 = 50

Anyway, I am including a working project Example in VisualStudio 2008 Format.

Diamonddrake 397 Master Poster

create a event handler for KeyDown for the textbox. then in the method add

if (e.KeyCode == Keys.Enter)
            {
                listbox1.Items.Add(textBox1.text);
            }

substitute the listbox1 for the correct name, and textbox1 for the appropriate name as well.

Diamonddrake 397 Master Poster

If you drop a picturebox control onto a form and set its SizeMode to zoom you will notice that no matter what you change the padding property to, it won't change the output.

The code for drawing the image in zoomed mode doesn't take in account the deflated rectangle it took the time out to create in the first place. just a simple change of scaling by the deflatedRectangle fixes the problem.

This method is called ImageRectangleFromSizeMode(SizeMode Mode);
create a new class inherit it from PictureBox, give it a constructor, override this method, and create a local version of the DeflateRect method and everything should work just fine. Although I did track down the problem, I actually created a new PictureBox control base with just these 2 methods from the original and much much more, Or else I would have just posted a working class.

Felt everyone should know about that error.

Diamonddrake 397 Master Poster

an idea would be to create a list of shapeobjects, and in the paint event loop through them and paint them to the panel, to determine if you are on the line of the rectangle create a smaller and larger rectangle, check if you are inside the larger but not inside the smaller one. this seems to work great. I used it to draw resizable circles on a picturebox for use in selecting eyes in a redeye removal feature.

The Idea would be not to raster them to the image until you were sure you were done moving them, unless you were interested in creating layers, which would be a different story entirely. Things can get complicated quick.

Diamonddrake 397 Master Poster

That's a good possibility Dan. Thanks for the suggestion. PicPro belongs to a photography studio, and inversely, picpro is also a Compiler app, Pict-Pro isn't in use, but is close to the latter. So i will continue to look, but It does seem to be a viable solution, that I may end up using, Thanks.

Diamonddrake 397 Master Poster

I have been working on an Picture adjusting/cropping/resizing/emailing app. Its concept is pushed toward looking similar to Adobe Lightroom, in that none of the adjustments affect the original images, and all the adjustments are reversible and appear on the main screen as a sidebar. The goal of the app it to make it easy to select a group of pictures, perform some simple adjustments, contrast brightness red eye, ect. then add them to a export list, then set the destination size for all the images to be resized to, a dest format, and naming scheme, then have it export the images and optionally adding them to a zip file and emailing them.

I tell you that, and ask you this. I can't seem to find a catchy professional sounding name for the app. All the names i come up with are already taken. So if anyone can toss out some suggestions, I would appreciate it.

I though of DigIDev, or DIDev (Digital Image Development Studio)
but both short names belong to internet companies. Everything else I think of just sounds dumb

Thanks.

Diamonddrake 397 Master Poster

I read up a little, There is a native method that asks for a graphics object to be pulled from a graphics object pool and assigned to a window handle. Each control does this, as does anything that inherits from the Control class.

There are a finite amount of graphics objects available, and creating them is resource expensive.

if you wish to create a graphics object not from a image but from a window using its handle you can using the graphics class.