Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › c# problem solved for now!
New Posts  All Forums:Forum Nav:

c# problem solved for now! - Page 2

post #11 of 24
Quote:
Originally Posted by zodac View Post
OK, so a bit of expansion. I basically want a loop, where a name/number will show up in a message box, but then count down. So this is what I was gonna try:

for (int i = 0; i < 10; i++)
MessageBox.Show(i);

However, Chris tells me that just makes 10 message boxes pop-up instead...
Anyway of having the new message replace the old one instead?
You should create your own message box routine and expose the text via a change function, or use a string somewhere other than a messagebox (like the label mentioned above). I don't program c#, but message boxes are not typically meant to be dynamic, they are meant to display a quick message in a specific instance.

It is probably not trivial to change the text, but I'm not sure. I'd make my own routine if you were going to be using the message boxes heavily in your application, something more suited to your requirements.

You can probably even find a library or example already written for this purpose.
Edited by _02 - 4/26/11 at 9:29am
    
CPUMotherboardGraphicsRAM
Phenom II X3 720 @ 3.5 (1.39v) Gigabyte GA-MA790XT-UD4P ASUS 5850 @ 880/1180 (1.118v) 4gb 1333mhz G.Skill DDR3 
Hard DriveHard DriveHard DriveHard Drive
64gb Crucial M4 SSD 3x 250gb WD2500JD - RAID0 1tb WD1001FALS 1tb WD10EARS 
Optical DriveCoolingOSMonitor
Pioneer DLDVD/CDRW Arctic Freezer Pro 64 Win 7 64bit Ultimate E2305 LG 23" LED 
KeyboardPowerCaseMouse
Filco Majestouch II Ninja Tenkeyless Fortron BlueStorm II 500w CM 690II Advanced Razer DeathAdder 
Mouse PadAudioAudio
generic Echo Miamidi PCI M-Audio BX5a Studio Monitors 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Phenom II X3 720 @ 3.5 (1.39v) Gigabyte GA-MA790XT-UD4P ASUS 5850 @ 880/1180 (1.118v) 4gb 1333mhz G.Skill DDR3 
Hard DriveHard DriveHard DriveHard Drive
64gb Crucial M4 SSD 3x 250gb WD2500JD - RAID0 1tb WD1001FALS 1tb WD10EARS 
Optical DriveCoolingOSMonitor
Pioneer DLDVD/CDRW Arctic Freezer Pro 64 Win 7 64bit Ultimate E2305 LG 23" LED 
KeyboardPowerCaseMouse
Filco Majestouch II Ninja Tenkeyless Fortron BlueStorm II 500w CM 690II Advanced Razer DeathAdder 
Mouse PadAudioAudio
generic Echo Miamidi PCI M-Audio BX5a Studio Monitors 
  hide details  
Reply
post #12 of 24
Just so it's clear, I'm not writing the code; Chris is. I'm just asking for things.

I'll ask him to come over.
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
post #13 of 24
Should look similar to this:

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

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

        public void newName(String newName)
        {
            nameLbl.Text = newName;
        }

        private void closeBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
Edit: If you guys want to add me on steam my ID is Farfnarkle, or feel free to PM me. I'd love to help
Edited by Farfnarkle - 4/26/11 at 9:36am
post #14 of 24
Thread Starter 
Quote:
Originally Posted by zodac View Post
However, Chris tells me that just makes 10 message boxes pop-up instead...
I never said that.


Jumping on Steam no I suppose...

Quote:
Originally Posted by Farfnarkle View Post
If you guys want to add me on steam my ID is Farfnarkle, or feel free to PM me. I'd love to help
Not working, add me - LiLChris305
Edited by LiLChris - 4/26/11 at 9:43am
>.<
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 4.0ghz 1.27v EVGA E758 3-Way (black/gray) Evga GTX 480 / Evga 9800gtx+ (physx&folding) Corsair Dominator 6gb 1600 8-8-8-24 
Hard DriveOSMonitorPower
x25-M SSD 80gb + 1TB F3 + 2x2TB WD Green Win 7 64bit Viewsonic 20" + Samsung 40" Corsair 1000w 
Case
Haf 932 (modded) - Now caseless 
  hide details  
Reply
>.<
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 4.0ghz 1.27v EVGA E758 3-Way (black/gray) Evga GTX 480 / Evga 9800gtx+ (physx&folding) Corsair Dominator 6gb 1600 8-8-8-24 
Hard DriveOSMonitorPower
x25-M SSD 80gb + 1TB F3 + 2x2TB WD Green Win 7 64bit Viewsonic 20" + Samsung 40" Corsair 1000w 
Case
Haf 932 (modded) - Now caseless 
  hide details  
Reply
post #15 of 24
Also, for the countdown:

Code:
using System.Timers;

//In the constructor for the message box
Timer timer = new Timer();
timer.Interval = 1000; //1 sec
timer.Elapsed += TimeElapsed;

private void TimeElapsed(object source, ElapsedEventArgs e)
{
  //Timer logic here, probably keep a variable to count down
}
Micro Dance
(8 items)
 
  
CPUMotherboardGraphicsRAM
i7-4790k z97i-plus EVGA GTX980 SC 16GB Team Xtreme 2400 
Hard DriveCoolingOSCase
512GB Samsung SSD 830 NH-L12 Windows 10 EVGA Hadron Air 
  hide details  
Reply
Micro Dance
(8 items)
 
  
CPUMotherboardGraphicsRAM
i7-4790k z97i-plus EVGA GTX980 SC 16GB Team Xtreme 2400 
Hard DriveCoolingOSCase
512GB Samsung SSD 830 NH-L12 Windows 10 EVGA Hadron Air 
  hide details  
Reply
post #16 of 24
You're going to need two forms and an if loop using
Code:
System.Threading.Thread.Sleep()
to slow down the loop when it display its results. Also call the new form on a on a button click by initializing it:
Code:
Form2 f2 = new Form2();
f2.show();
and in the constructor class of Form2 make your loop and in the end of it put that Thread.Sleep(500) line so the loop will stop for half a second before it displays the next results.

Really dirty code but I quote _02:
"I don't program c#, but message boxes are not typically meant to be dynamic, they are meant to display a quick message in a specific instance."
Edited by csm725 - 4/26/11 at 10:01am
Turbulence
(19 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5-2500k 4.4GHz Asus P8P67 Pro 3.1 HIS HD 7870 2GB G.SKILL Ripjaws X 16GB 1600MHz 
Hard DriveHard DriveOptical DriveCooling
Crucial m4 128GB Samsung Spinpoint F3 1TB Asus DRW-24B1ST Noctua NH-D14 
CoolingOSMonitorKeyboard
Accelero Twin Turbo II Windows 7 Professional N Dell U2311H Realforce 87U White 55cN 
PowerCaseMouseMouse Pad
Corsair TX650V2 Fractal Design R3 Black Pearl Razer DeathAdder SteelSeries 4HD 
AudioAudioAudio
Audinst HUD-mx1 Beyerdynamic DT990 Premium 600 Ω Recabled M-Audio AV40 
  hide details  
Reply
Turbulence
(19 items)
 
  
CPUMotherboardGraphicsRAM
Intel i5-2500k 4.4GHz Asus P8P67 Pro 3.1 HIS HD 7870 2GB G.SKILL Ripjaws X 16GB 1600MHz 
Hard DriveHard DriveOptical DriveCooling
Crucial m4 128GB Samsung Spinpoint F3 1TB Asus DRW-24B1ST Noctua NH-D14 
CoolingOSMonitorKeyboard
Accelero Twin Turbo II Windows 7 Professional N Dell U2311H Realforce 87U White 55cN 
PowerCaseMouseMouse Pad
Corsair TX650V2 Fractal Design R3 Black Pearl Razer DeathAdder SteelSeries 4HD 
AudioAudioAudio
Audinst HUD-mx1 Beyerdynamic DT990 Premium 600 Ω Recabled M-Audio AV40 
  hide details  
Reply
post #17 of 24
Quote:
Originally Posted by zodac View Post
OK, so a bit of expansion. I basically want a loop, where a name/number will show up in a message box, but then count down. So this is what I was gonna try:

for (int i = 0; i < 10; i++)
MessageBox.Show(i);

However, Chris tells me that just makes 10 message boxes pop-up instead...

Anyway of having the new message replace the old one instead?
As there is no overload for MessageBox.Show that takes an int parameter, what you actually get is a compilation error.

MessageBox.Show is a blocking call. That means that once you have converted it to a string (string.Format("Countdown: {0}", i), for example) it will stay there and no code will execute in that thread until you dismiss it. When you dismiss it, the loop will pass and the next will appear.


If you really wanted a message box to do something like disappear after an amount of time (so that another could be displayed in its place) or change the text on it, you could probably just derive a new class from it. MessageBox is not sealed, after all.

For changing the text you would need to both change the string being displayed and update/repaint the control. A .net MessageBox is only a thin layer over its Win32 API counterpart, so going back to that could get you access to things you wouldn't normally be able to touch.

System.Windows.Forms.CommonDialog is another alternative base class to Form.

You can also read about non-blocking MessageBoxes.


You're probably best off finding a better way to display it though. Console output, changing the value of a label already on your form or something. If you need weird workarounds like this, you're clearly doing something wrong.
Edited by ghell - 4/26/11 at 10:36am
Serene Power
(13 items)
 
  
CPUMotherboardGraphicsRAM
Dual Xeon E5620 Supermicro X8DAL-i EVGA 570HD SC 8GiB Corsair DDR3 1333 ECC-R 
Hard DriveOptical DriveOSMonitor
OCZ Agility 3 120GB SSD (+16TB NAS) LG 10x Blu-Ray Windows 7 x64 / Debian x64 Dell 2408WFP, P2411H 
PowerCase
850W CoolerMaster SilentPro M CoolerMaster Cosmos Pure 
  hide details  
Reply
Serene Power
(13 items)
 
  
CPUMotherboardGraphicsRAM
Dual Xeon E5620 Supermicro X8DAL-i EVGA 570HD SC 8GiB Corsair DDR3 1333 ECC-R 
Hard DriveOptical DriveOSMonitor
OCZ Agility 3 120GB SSD (+16TB NAS) LG 10x Blu-Ray Windows 7 x64 / Debian x64 Dell 2408WFP, P2411H 
PowerCase
850W CoolerMaster SilentPro M CoolerMaster Cosmos Pure 
  hide details  
Reply
post #18 of 24
Thread Starter 
PM me on Steam if you want to help, right now Farfnarkle is trying but is stuck.

If you get frustrated I would like to note this is the request of zodac!
>.<
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 4.0ghz 1.27v EVGA E758 3-Way (black/gray) Evga GTX 480 / Evga 9800gtx+ (physx&folding) Corsair Dominator 6gb 1600 8-8-8-24 
Hard DriveOSMonitorPower
x25-M SSD 80gb + 1TB F3 + 2x2TB WD Green Win 7 64bit Viewsonic 20" + Samsung 40" Corsair 1000w 
Case
Haf 932 (modded) - Now caseless 
  hide details  
Reply
>.<
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 930 4.0ghz 1.27v EVGA E758 3-Way (black/gray) Evga GTX 480 / Evga 9800gtx+ (physx&folding) Corsair Dominator 6gb 1600 8-8-8-24 
Hard DriveOSMonitorPower
x25-M SSD 80gb + 1TB F3 + 2x2TB WD Green Win 7 64bit Viewsonic 20" + Samsung 40" Corsair 1000w 
Case
Haf 932 (modded) - Now caseless 
  hide details  
Reply
post #19 of 24
Quote:
Originally Posted by zodac View Post
OK, so a bit of expansion. I basically want a loop, where a name/number will show up in a message box, but then count down. So this is what I was gonna try:

for (int i = 0; i < 10; i++)
MessageBox.Show(i);

However, Chris tells me that just makes 10 message boxes pop-up instead...

Anyway of having the new message replace the old one instead?
How do you want to specify the Name and starting number? Is this just counting down seconds?
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
TheHydra
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7 860 @ 3.6 EVGA P55 FTW Sapphire TOXIC 2GB 6950 CORSAIR XMS3 4 x 2GB CMX4GX3M2A1600C7 
Hard DriveOSKeyboardPower
C300 64Gb + 2x F3 HD103SJ 1TB in RAID 0 Win7 x64 Razer BlackWidow Corsair 750HX 
CaseMouseMouse Pad
Lian Li A05NB with 140mm top fan. Razer DeathAdder Razer Kabuto 
  hide details  
Reply
post #20 of 24
Ok, so almost done now; all previous problems have been solved.

Now... if we're reading in a list from a file, would there be a way to delete each line as it's chosen, so it wouldn't come up more than one time (or a set number of times)?
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
Megadoomer
(14 items)
 
Family Computer
(13 items)
 
 
CPUMotherboardGraphicsRAM
Phenom II X6 1090T @ 4.0Ghz ASUS M4A89GTD PRO Sparkle GTS 450 2x4GB G-Skill Sniper 
Hard DriveCoolingOSMonitor
Samsung F1 1TB CM Hyper 212+ Windows 7 Professional x64 Samsung T220 
KeyboardPowerCaseMouse
Logitech MX3000 Laser CM 1000M HAF 922 Logitech VX Revolution 
CPUMotherboardGraphicsRAM
Q6600 Asus PN5-D 750i Evga GTS 250 2x2GB Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
750GB Hitachi Samsung Super Writemaster Windows 7 Professional x64 19" Dell 
PowerCase
Corsair 450VX Antec 900 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › c# problem solved for now!