Diamonddrake 397 Master Poster

there are quite a few ways to do this, simplest

string path =  Application.StartupPath;
//This gets the directory the application was started from.

And more complicated, but many people will tell you this is the only correct way, I argue against that. but it certainly does work also.

string correctPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
Diamonddrake 397 Master Poster

you aren't adding the new picture box to the form's controls collection, so it doesn't get painted.

after you set the new picturebox's properties. add

This.Controls.Add(pictureBox);
Diamonddrake 397 Master Poster

in sudocode:
onPicturebox MouseDown:

create new picturebox

set new picutebox's size, location, and image properites
to match the old picturebox

StartDraging code moving the new picutebox not the old one.

onMouseUp leave new picutebox where ever you left it/ want it.

Diamonddrake 397 Master Poster

IDK about that one. COM works with running apps. but I'm afraid that's where my usefulness here looses speed. Sorry. Hope you find your answer.

Diamonddrake 397 Master Poster

Yes you can. That's what I explained before. Create a public class with a pubic method GetBookReference(string book) or whatever you want. Compile it. and start a new application. Click on references. Click new reference. and browse to the first exe. then use the GetBookReference(string book) method. That simple. Just try it

that is assuming that you are using Visual Studio 2008. I believe older versions of Visual studio limits you to .dll even then you can manually add a reference using compiler arguments.

I just tested it in Visual studio 2008 to verify that it works, and it does.

Diamonddrake 397 Master Poster

The System.Drawing name space holds a class called Image. It is used as a type and has instance methods. It cannot be directly initialized but is easily used a runtime.

Image pic = Image.fromFile("path to image");
then you can show the image anyway you like, as the image property of a picturebox or in a drawimage method in the paint event.

or even short cut it. Picturebox1.Image = Image.FromFile("where file is");

But more importantly the picturebox has a ImageLocation property that is a string. set that to a path to a file, and it will load the image.

All of these methods work from run time, not build time.

Diamonddrake 397 Master Poster

the 2nd form should expose the selected data as properties. when the user has set the values they wanted. the dialogresult property should be set to OK. and the form closed. Nothing else needs to happen in the 2nd from. The main form will still have a reference to the 2nd form and be able to get its data.

Diamonddrake 397 Master Poster

The dialog modal of programming suggests that you get the data from the edit dialog back to the main form. not the other way around. your OK button should just close the form with the dialogresult property set to true. and expose the color font and text from the edit dialog as properties. Then do it all in the method that calls the edit dialog.

//code on main form.
    private void toolStripButton1_Click(object sender, EventArgs e)
    {
        EditText myNewForm = new EditText(); 
       if(myNewForm.Showdialog() == dialogresult.OK)
       {
          Image img = picturebox.image;
         Graphics G = Graphics.FromImage(img);
         G.DrawString(myNewForm.BodyText, myNewForm.BodyFont, new SolidBrush(myNewForm.BrushColor), new PointF(0, 0));
          G.Dispose();
          picturebox.image = img;
           picturebox.Invalidate(false);
       }

}

Keep in mind this code is for example only, written here to explain the concept. It doesn't have correct names for your project, assumes changes are made that aren't shown to the original code, contains spelling and capitalization errors, etc. Give you the idea of how it should look though.

Diamonddrake 397 Master Poster

call the open file dialog box in the program's Main method. if its a success then call the application.run method passing the filename to the form's constructor. if its not a success then simple allow the main method to return closing the program.

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Serial
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1(ofd.FileName));
            }
        }
    }
}
Geekitygeek commented: word for word what i would have post :p +1
Diamonddrake 397 Master Poster

Saving reading every line of code here. I think what you are going for is to expose the values your text dialog has as properties. and when the method that calls it returns, get those values and apply it to the image and refresh the picturebox.

Diamonddrake 397 Master Poster

it would be helpful if you just post your project. we can find out what is really going on.

Diamonddrake 397 Master Poster

this isn't very clear. But with only this information i would say check the file extensions on the path. if its .PDF then obviously, and if its .jpeg, .gif, .png, .bmp, ect. then its an image.

Diamonddrake 397 Master Poster

Some thoughts on this:

1) When using multiple forms for 1 application, its advantages to use MDI. Most users like to feel they have control over what they are doing and a bunch of floating forms can be scary if they don't behave the norm. Typically the "Main" form is just a container. and then multiple other forms populate that space with information.

2)in the Main method of the application the static application class's "RUN" method gets called. this is what creates the message loop that keeps your main method from returning until the Message Loop is exited. In your Main method you will see that the run method is taking a new instance of your main form. This means that the message loop is tied to the life of that instance. when you close it. "RUN" returns and the Main method returns.
You could easily create a new form and show it then call and empty RUN() method, then when the forms close the app would stay running until the process was killed externally. Or create a ApplicationContext that would tell the program what to do when a form is closed.

Diamonddrake 397 Master Poster

As long as the methods don't need the application to be running to work, then you simply put them in a public class, and make the methods public, then reference the .exe from the new app. and all its public classes and methods will be available to other applications.

Diamonddrake 397 Master Poster

Those guidelines were written by some cleaver programmers, There is no "official" standard. But there is always the Standard microsoft uses in its coding examples on MSDN.

I would argue to the OP that I don't think alphabetical is the best practice or even relevant. If you use Visual Studio (and everyone should because its amazing) you will notice that there is a combo box at the top of ever code view that lists all the members of the current document in alphabetical order. click on one and you are there.

Not saying that coding practice's aren't important, Because its very important that you are consistent. I Just don't feel that the order of your code should at all be based on access modifiers. Nor do I feel that all members with similar access modifiers even be kept together.

Best of luck. Learning to keep your code clean at the beginning can lead to a career of easy to review code.

Diamonddrake 397 Master Poster

That's up to you or whoever reviews your code. If you write apps alone. Its whatever is easiest for you.

Personally I order code by relevance. I create some regions and put similar things together. I put the private variables and the public properties that expose them right next to each other in a vars and properties region. I put the load event toward the top, and the on closing event toward the bottom.

When the program compiles its all one big sheet of code anyway. There isn't a right way. (unless you work for a company that cares, in which case, do what they ask)

Diamonddrake 397 Master Poster

In a for loop you have to use a local variable that you create in the first part of the loop. you cannot use a variable created somewhere else.

if you want to use vars created somewhere else use a while loop.

while(i < n)
{
   textBox2.Text += " " + Convert.ToString(i);
    
   i++;
}
Diamonddrake 397 Master Poster

Application.Run(form) doesn't return until the form is closed. So it would actually be a perfect place to end any background threads started with an application scope. Although you may still want to join the threads just to make sure that the background thread as stopped before the Main method returns.

Diamonddrake 397 Master Poster

The CultureInfo class holds culture-specific information, such as the associated language, sublanguage, country/region, calendar, and cultural conventions.

This just creates an array of cultureInfo classes by asking the system for all that it knows about, then attempts to extract a string from that object representing the culture's country.

The line where you get the error is where you are creating a regionInfo object that accepts a culture Identifier. The error you get is that one of the culture's in windows 7 allows the "invariant culture" object to show up when you ask for all cultures this way. and "invariant culture" represents an empty culture object with the ID 0x007F (or 127)

so we just check for that and it will work. just replace your getCountryList method to this one and it will all work fine.

public static List<string> getCountryList()
        {
            List<string> cultureList = new List<string>();
            CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);

            foreach (CultureInfo culture in cultures)
            {
                if (culture.LCID != 127)
                {
                    RegionInfo region = new RegionInfo(culture.LCID);
                    //RegionInfo region = new RegionInfo(culture.LCID);

                    if (!(cultureList.Contains(region.EnglishName)))
                    {
                        cultureList.Add(region.EnglishName);
                    }
                }
            }

            cultureList.Sort(); //put the country list in alphabetic order.

            return cultureList;
        }

As for the KeyPressed and KeyDown events. Key pressed is when "some" keys are both depressed and released. and KeyDown is when any key is pressed down. but fires before its released. There are tons of articles out there about it. If you want to know more about using them in a error handling fashion ddanbe …

Diamonddrake 397 Master Poster

I don't see how it would relate to the monitor as points are points and widths are widths regardless of aspect ratio. have you tried compiling the code without changing it on another computer. to see it is definitely the computer in question?

Diamonddrake 397 Master Poster

It appeared to me that the OP was trying to prevent the button from getting focus by using the arrow keys. So that the user couldn't cheat and just focus the button and hit enter.

if the button was disabled it would be grayed out and the user probably wouldn't even try to click the button so 1.1 would have been pointless.

But it does seem like an odd homework assignment.

Diamonddrake 397 Master Poster

just put it in the body of the form. just like you would any other method.
Overrides replace a method in the class's baseclass, this method overrides the proccess command key method of the control class and stops it if it gets an arrow key.

If you can handle C++ then C# will come simple to you. Don't be afraid to read. There are a MILLION C# books out there. or you can experiment as I do. Visualstudio's intellisense really helps you explore a class's possibilites.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Joks1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((keyData == Keys.Right) || (keyData == Keys.Left) ||
                (keyData == Keys.Up) || (keyData == Keys.Down))
            {
                //Do custom stuff or nothing.
                //true if key was processed by control, false otherwise
                return true;
            }
            else
            {
                return base.ProcessCmdKey(ref msg, keyData);
            }
        }

        Random rnd = new Random();

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form2 jaunaForma = new Form2();
            jaunaForma.Show();
        }

        private void but_ja_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Text........","Joke...",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            this.Close();
        }

        private void but_ja_Move(object sender, MouseEventArgs e)
        {
// this part moves the 'yes' button around.
            but_ja.Top=rnd.Next(this.Size.Height-2*but_ja.Size.Height);
            but_ja.Left=rnd.Next(this.Size.Width-2*but_ja.Size.Width);
        }
    }
}
Diamonddrake 397 Master Poster

The arrow keys are processed differently as they are caught by the form its self. So in order to do this you must override that method that catches them.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ((keyData == Keys.Right) || (keyData == Keys.Left) ||
                (keyData == Keys.Up) || (keyData == Keys.Down))
            {
                //Do custom stuff or nothing.
                //true if key was processed by control, false otherwise
                return true;
            }
            else
            {
                return base.ProcessCmdKey(ref msg, keyData);
            }
        }

This code snippet is from Sknake here on the forum. He answered a similar question of mine about a year back.

Diamonddrake 397 Master Poster

SQL lite its a server technology that has to be installed on the system to use. MS access requires nothing to be additionally installed. that's what I like about it. Although, its not optimal for heavy usage for many simultaneous users, That's why most people speak poorly of it. But if the database only needs to be accessed by 1 computer/ user at a time. Its a pretty good system. I used it for a program that helps track my bills. 2GB worth of data now and still working strong. Even used it to store information for the guest book on my website.

The only problem with these new OSes such as Vista and 7 is your application cannot write to the Program Files directories. So remember once your application gets chugging along to save the Database in a document folder!

Diamonddrake 397 Master Poster

MSAccess requires nothing to be installed. SQLlite requires SQL lite server to be installed. But if you really want to make the switch just duplicate the tables in the new database and write a little loop that gets all the info from the first database table and creates objects in a list. then loop through the list and save the objects to the new database.

Should be pretty simple.

Diamonddrake 397 Master Poster

I personally have no scrape with MS ACCESS as aside from changing the connection string the code is all the same. C# is perfect for this project. Just to clear it. C# can do everything VB can, and any VB code can be converted to C# very simply. there are hundreds of code converters out there. So if you find code in VB just convert it over if you need to. http://converter.telerik.com/ is pretty good.

I'm not the best person to help with database apps but Visual studio has TONS of tools for it. even a SQL query builder, but I would suggest finding a good Object Relation Mapping library to save yourself some headache.

Best of luck on your project. I admire that you had a problem and decided to tackle it head on. That's how I learned everything I know about programming. up to 4 languages now and still moving forward!

Diamonddrake 397 Master Poster

Using resources can be easily updated if you use an "languages" dll and have your app check for update versions from a webserver. but the XML approach isn't a bad one, just its important for speed that you don't access the file every time you need the information. Disk access is slow and so is parsing XML. if the form has a lot of text on it there could be a delay of opening a new form which can be annoying.

If you create an object in your application with all static members that match your language text, at application start you can check the language of the OS or Language setting and load all the information to the Language object then when new forms open you can use the Language object to get the necessary text.

But to each their own. I don't think there is a "best way" but there are many good ways. if you wanted to be far fetched you could use one of those google translation apis and have your application make web queries and just translate the English version on the fly using the web and instantly support any translation that api does. I wouldn't recommend it, but it could work. :)

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

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

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

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

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

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

you could in theory take your image and load it in as a byte array, not as an image, sift through the bytes and find the start of the image data, then apply them there, but idk what the results would be. but other than that. there isn't sorry.

TotoTitus commented: Very relevant. +1
Diamonddrake 397 Master Poster

your extention was jpg but the image was NOT a jpeg. extensions mean nothing. Listen.

1. If you want to preserve your changes you cannot compress it, because compression codecs change those values.

2. Saving as a BMP is uncompressed, So it will work, but the file will be big.

3. if the file is big, then its uncompressed, and your data is preserved, if the file is small, then its compressed and you WILL LOOSE YOUR CHANGES

sorry that's how Imaging works.

Diamonddrake 397 Master Poster

the idea behind JPEG image compression is that it removes color differences that are not apparent by the human eye. If you really want a full quality picture you might want to always save to bmp or png24 regardless of source type.

jpeg compression looks good, and makes for a good file size, but if your goal is just to preserve bytes written into your image, you probably will loose it during the compression. Sorry. its still not clear to me what your goal is.

Diamonddrake 397 Master Poster

I ment size as in file size not dimensions. sorry.

// We will store the correct image codec in this object
            ImageCodecInfo iciJpegCodec = null;
            // This will specify the image quality to the encoder
            EncoderParameter epQuality = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (int)80);//set quality here
            // Get all image codecs that are available
            ImageCodecInfo[] iciCodecs = ImageCodecInfo.GetImageEncoders();
            // Store the quality parameter in the list of encoder parameters
            EncoderParameters epParameters = new EncoderParameters(1);
            epParameters.Param[0] = epQuality;

            // Loop through all the image codecs
            for (int i = 0; i < iciCodecs.Length; i++)
            {
                // Until the one that we are interested in is found, which is image/jpeg
                if (iciCodecs[i].MimeType == "image/jpeg")
                {
                    iciJpegCodec = iciCodecs[i];
                    break;
                }
            }
         
//now save
                yourImage.Save(filepath, iciJpegCodec, epParameters);

I borrowed this code from somewhere a long time ago, i don't remember where. there are other ways. but this one always worked for me.

Diamonddrake 397 Master Poster

if the image is a different size, its probably the compression level. when you save your bitmap, if you save it as a jpeg file, you can alter its compression methods, changing its filesize, if you just call save, it uses the default. which might be different from the source image.

Diamonddrake 397 Master Poster

I'm not sure what you mean about it requiring that you override some methods. But that's not your problem. You added a reference to the debug dll of the class library, when your class library is in the same project you add a reference using the "project" tab of the add reference dialog. I made this switch and now everything works as it should and the logincontrol appears in the toolbox at the top.

here is the fixed project and a screen cap.

Diamonddrake 397 Master Poster

Do your controls inherit from UserControl or Control? if they don't inherit from one of those they can't be added.

Furthermore, Its likely that you custom control doesn't have a public constructor. and there should be a constructor that takes 0 args, even if your control needs to take some args, in order for the toolbox to work right there needs to be one with 0 args.

hope this helps. Its hard to help without seeing the code.

try this, create a new project, add a new class call it mybutton, then change it to inherit from System.Windows.Forms.Button save it and compile. then close the empty for that appears, and look in the tool box, at the very top there should be a gear icon with "mybutton" next to it. It should be that simple.

Diamonddrake 397 Master Poster

Depending on your settings it might not. Rightclick on the toolbox and select "choose items" browse to your library and select the controls from it you want to see in the toolbox.

Diamonddrake 397 Master Poster

Instead of reading the bytes and doing the calculation, or by directory, why now go half way, just count all the files to be scanned, then increment it as it finishes files...

DdoubleD's way would be the most accurate, and Ryshad's way would be the fastest, Just counting all the files would be significantly faster than the first method, but more accurate than the second.

Guess its all up to your taste. Speed or accuracy.

Everyone dissed on the file copy and transfer time remaining calculations on XP, so Vista and 7 spend more time calculating the time it will take. Now the time remaining estimation is significantly more accurate, but it takes extra time calculating instead of transferring files, so its actually slower to copy or move files now thanks to that accuracy calculations. - a person like myself, cares about how long it will take only because I wish it would go faster.

Diamonddrake 397 Master Poster

IF you want to affect the first form, why would you create a new instance of it? What you need to do is pass THE instance of the first from to the second form. then act upon that instance, easy.

//this is form1's button click to open preference from 2

private void prefferencesbtn_click(object sender, EventArgs e)
{
      Form2 prefs = new Form2(this); //the secret!
      prefs.Show();
}

//now the form2 needs to catch this instance and hold it.

Form MainForm;//create class var to hold form1 instance.
//constructor for form2
Public void Form2(Form mForm)
{
     //catch the instance
    MainForm = mForm;
}

//now your code

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "800x600")
            {
                MainForm.ClientSize = new System.Drawing.Size(800, 600);
            }
            if (comboBox1.Text == "300x300")
            {
               MainForm.ClientSize = new System.Drawing.Size(300, 300);
            }
        }

Happy Coding!

Diamonddrake 397 Master Poster

a separate picture box for each image yes, your bottleneck in performance will be loading the images from disk, Creating a new image using the images is just an extra step that is even slower, a few picturebox controls won't suffer you any performance. Its the images that they hold in memory that makes a difference. But 10 little picures and one big picture made of the little pictures will take up the same amount of memory. But your system will actually handle many little pictures better than a very big one.

But before you go trying to reinvent the wheel try the imagelistview control from code project.

Its probably the most amazing free control i have ever seen, and its very customizable. check it out! http://www.codeproject.com/KB/list/imagelistview.aspx The guy said it can easily handle thousands of images, and just playing around with it, I open my entire MY Pictures folder containing over 1000 images and it handled it just fine, smooth scrolled and looks great.

Diamonddrake 397 Master Poster

The way you are doing it isn't bad, you just aren't using the buffer idea correctly, the paint event should just draw the buffer image, nothing else. all the other stuff including the loop should be done in a loadthumbs method, what you have accomplished is to reload the images and draw them to disk EVERY time the picbox invalidates.

but a better way to do it would be to use multiple picture boxes on a user control, the picturebox has a Asynchronous image loading method build into it. So it would be very simple!

create a usercontrol that has a collection of image locations as a property, when the property is changed, have the usercontrol loop through and create a picturebox for each element in the collection and load the images using the Asynchronous load method of the picturebox. And presto, easy, fast, effective, and elegant control, that is reusable, and fits your needs.

Diamonddrake 397 Master Poster

I don't recommend using wmp.dll, but I do recommend using directshow. Windows is built around directX. included in directX 10 and higher is the directX managed libraries that supply you with video and sound objects that are very simple to use.

DirectShow automatically builds a filter graph for video so you don't have to do it manually. that's how windows media player does it. the only real alternative is to manually build the filter graph, but I don't know why one would bother.

as for the skin. the simplest way is just to create custom drawn controls for each part you need. But if you are looking for some good grades you could write a skin engine and create a DLL full of resource images and have a loop that goes through them and applies the matching resource named images to matching named controls allowing they to be easily changed by changing which dll is loaded, and have it loaded by reflection so it can be easily switched out. (a folder of images or zipfolder could work equally well).

best of luck.

Diamonddrake 397 Master Poster

um... What?