|
A few changes to your FormSplash should make it work.
add a delegate to your class to handle the form closing
delegate void CloseDelegate();
Add a method to handle the delegated form closing in a thread safe manner:
void DoClose()
{
if (this.InvokeRequired)
{
CloseDelegate d = new CloseDelegate(DoClose);
this.Invoke(d);
}
else
{
while (ms_frmSplash.Opacity > 0)
{
this.Opacity -= m_dblOpacityDecrement;
System.Threading.Thread.Sleep(TIMER_INTERVAL);
}
this.Close();
}
}
Change the CloseForm method to read:
static public void CloseForm()
{
if (ms_frmSplash != null && ms_frmSplash.IsDisposed == false)
{
ms_frmSplash.DoClose();
}
ms_oThread = null;
ms_frmSplash = null;
}
Note also I used the following values:
static int TIMER_INTERVAL = 1 * 1000;
double m_dblOpacityIncrement = .1;
double m_dblOpacityDecrement = .1;
[edit]
Updated to use proper cross-thread checking
[/edit]
modified 10-Apr-15 9:09am.
|
|
|
|
|
Thanks for bailing my rear out on this again Richard.
Works like a charm!, and the fade is really slow, but hey it works.
Why the 1 * 1000 on the timer interval?
I figured out it was a thread issue, but between this being my first 100% c# Windows Form App and learning more c#, it was a brain overload for me.
CloseDelegate DoClose
[FYI]
I bought a subscription to outsource.com, and scored my first job in 7 days. It was the only Microsoft Job that I had seen posted so I went for it. I had to learn c# anyways, and could use a library of code functions for later use.
So I figured what the heck and put a competitive price out for it and got the job. I should be done by today.
Interesting, the customer is a VB6 programmer, and wanted to test the concept of using one DAL for a Win App, MVC 5, and a WPF project as a single source of data using Entity Framework. So I thought I was going to do a MVC 5 Job, but turned out to be a C# win app. Pretty cool, the DAL gets compiled as a DLL, and can be used by all the program types.
Thanks Richard!
|
|
|
|
|
Happy to help, Jim.
The 1 * 1000 (1 second) on the timer interval was just an arbitrary choice so I could see clearly what was happening. You can adjust it to your own requirements. Similarly the 0.1 (10%) on the m_dblOpacityDecrement is arbitrary. Just have a play with the numbers until you get the effect you want.
|
|
|
|
|
okeedokey on that.
I'll may be back here shortly so stay tuned.
Now I have to sort on Entity Framework, in which I've never used before.
|
|
|
|
|
This is my first c# Windows Form App that I'm working on here.
It worked fine, then I started modifying it, and I get this error in program.cs
I moved the form files into new folders to stay organized.
So I created a new project and double checked the project properties, and the main form code plus program.cs code and there identical. I don't get it.
History, c# is new to me, I code in VB.
Application.Run(new FormMain());
|
|
|
|
|
Sounds like your FormMain class doesn't have a parameterless constructor. You should have something like:
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oh,
I added the event arg to that and forget about it.
This seems really different than a VB Form App
Thanks Richard!
|
|
|
|
|
jkirkerx wrote: This seems really different than a VB Form App
No, it's identical!
And why on earth would you "add the event arg" to a form constructor? IN C# or VB?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I had no clue what I was doing. I had never really seen a c# Windows App before, and thought it was required. Well that bit me in the rear. But I'm floating above water now on this and starting to pick it up faster.
I got my Registry stuff working, learned ByRef vs ref. Didn't know VB had some helpers that made coding really easy, I guess I just need to learn the c# equivs.
|
|
|
|
|
jkirkerx wrote: Didn't know VB had some helpers that made coding really easy,
It does...but...they tend to bite you in the ass at run time, where C# tends to catch them at compile time which makes development quicker and improves reliability.
Bear in mind that VB and C# are the same "under the hood" and are in fact interchangeable (there are online tools that will do it for you - pretty well from C# to VB and "so-so" from VB to C# because it's only context that differentiates methods from arrays in VB - so have a look at them as well, but don;t rely on them to make you a "good" C# coder by writing it all in VB!
http://converter.telerik.com/[^] works pretty well.
http://www.developerfusion.com/tools/convert/csharp-to-vb/[^] I prefer, but it doesn't always work - gets overloaded I suspect.
Please, don't use the registry for new apps - it's restricted and likely to get more so thanks to the massive abuse it got in the early days. It's pretty easy to store data without the registry: Where should I store my data?[^] may help.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I used the 2nd converter reference I got from Sergey. It's pretty good, but the small stuff like int.Parse reacted different than in VB, and string.replace as well which I replaced with regex.
I can see how c# seems to catch things in development before I find out the hard way later in deployment. And I can see how I could of wrote it better in VB.
Didn't know about the registry. I was just storing the main window location and size there in the HKCU, thought that was OK to do since my last research on the subject in the days of Vista and Win7.
|
|
|
|
|
Hello,
I'm using a website to parse data to my program and I return the node I want and add it to a listbox. In this case I am looking for "GameTitle". "GameTitle" has a sibling called "id". Once a "GameTitle" is selected in the listbox I would like to pass the id to a variable called "id". I am a bit stuck now and would appreciate some help.
Snippet of XML
<Data>
<baseImgUrl>http:
<Game>
<id>5016</id>
<GameTitle>Final Fight</GameTitle>
<PlatformId>21</PlatformId>
<Platform>Sega CD</Platform>
<ReleaseDate>07/01/1993</ReleaseDate>
<Overview>
The Sega Mega CD version, titled Final Fight CD, was ported and published by Sega under license from Capcom in 1993. This version retains nearly all the features of the arcade game (namely the 2-player game mode, the Industrial Area stage, and the ability to play as any of the three main characters), adding voice acting to the game's opening and ending sequence, an arranged version of the original soundtrack, and an exclusive time attack mode. The Mega CD version was still censored for the English localization with many of the same changes. Poison and Roxy were kept this time, but were redrawn with less revealing clothing (longer shorts and shirts) to hide all nudity
</Overview>
<Genres>
<genre>Fighting</genre>
</Genres>
<Co-op>No</Co-op>
<Publisher>Sega</Publisher>
<Developer>Sega</Developer>
<Images>
<fanart>
<original width="1920" height="1080">fanart/original/5016-1.jpg</original>
<thumb>fanart/thumb/5016-1.jpg</thumb>
</fanart>
<boxart side="back" width="1530" height="2156" thumb="boxart/thumb/original/back/5016-1.jpg">boxart/original/back/5016-1.jpg</boxart>
<boxart side="front" width="1539" height="2156" thumb="boxart/thumb/original/front/5016-1.jpg">boxart/original/front/5016-1.jpg</boxart>
<clearlogo width="400" height="250">clearlogo/5016.png</clearlogo>
</Images>
</Game>
My Code Snippet
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;
using System.Xml;
using System.Collections;
using System.IO;
using System.Xml.Linq;
using System.Net;
namespace Collection
{
public partial class search : Form
{
ArrayList ar;
String Search_Query;
public string id;
public string selectedGame;
public search()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Search_Query = textBox1.Text;
URL_XML_Load();
}
public void URL_XML_Load()
{
XmlDocument doc = new XmlDocument();
doc.Load("<a href="http:
foreach (XmlNode node in doc.ChildNodes)
{
if (node.Name == "Data")
{
foreach (XmlNode node_of_node in node.ChildNodes)
{
if (node_of_node.Name == "Game")
{
string Name = node_of_node["GameTitle"].InnerText;
listBox1.Items.Add(Name);
}
}
}
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
selectedGame = listBox1.SelectedItem.ToString();
}
|
|
|
|
|
Try something like this:
public void URL_XML_Load()
{
XmlDocument doc = new XmlDocument();
doc.Load(...);
foreach (XmlNode game in doc.SelectNodes("Data/Game"))
{
string id = game["id"].InnerText;
string name = game["GameTitle"].InnerText;
listBox1.Items.Add(new GameItem(id, name));
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
GameItem selectedItem = (GameItem)listBox1.SelectedItem;
id = selectedItem.Id;
selectedGame = selectedItem.Name;
}
...
public sealed class GameItem
{
public string Id { get; private set; }
public string Name { get; private set; }
public GameItem(string id, string name)
{
Id = id;
Name = name;
}
public override string ToString()
{
return Name;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That works great but I receive a
"Object reference not set to an instance of an object." id = selectedItem.Id;
on the second search, I presume this is because the item is still selected, so I tried
listBox1.ClearSelected();
selectedItem = null;
|
|
|
|
|
If you clear the selection, there won't be a selected item.
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
GameItem selectedItem = (GameItem)listBox1.SelectedItem;
if (selectedItem == null)
{
id = null;
selectedGame = null;
}
else
{
id = selectedItem.Id;
selectedGame = selectedItem.Name;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Try this
if (node_of_node.Name == "Game")
{
string Name = node_of_node["GameTitle"].InnerText;
listBox1.Items.Add(Name);
id= node_of_node["GameTitle"].previousSibling.InnerText
<pre>
}
|
|
|
|
|
How to generate a sequence of number prefixed with a character.
eg: a0001, a0002 ..... I need the character a to be prefixed to the 4 digit number.
additional info: I'm using VS 2010 SQL management studio 2005
I'm a newbie trying to build a website
thanks in advance.
|
|
|
|
|
Try the following statement
String result = String.Format("a{0:0000}", i);
in a loop. i is the looping variable. Probably will you need to store or display the results somewhere.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Where do you need this value? Rather than trying to generate or store this value, you could simply create this value when you select it from the database. Something for you to consider first - is 9999 going to be the maximum value in this sequence?
Are you printing out a list that doesn't exist, and that you don't want to store in a database? Do you actually need to use the database at all, considering that you have posted this in the C# forum?
|
|
|
|
|
ya! i need to generate the sequence number and store it in sql DB
|
|
|
|
|
No, you don't need to store it in exact the same way you present it. It is compound data, and consists of a prefix and an (unformatted) number.
To save "a00001", you'd use a identity-field to generate the number. Saving redundant zeros isn't going to help much, and you'd loose the ability to use the real number. You can combine both facts in a view, adding the prefix to the number and adding some formatting. That way the number would always be in the format you desire when someone fetches it from the database, while also having the advantage to be able to use the number as a real field to select on.
Otherwise there's a big chance that you'll need a "part" of that compound number in a query, and be forced to "substring" the field. That'd be a major cause for slow queries.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In addition to what Eddy Vluggen mentioned. I assume that "a" prefix has a purpose. Else it would not be necessary. Therefore other prefixes are possible too ("b", "c", "helloworld", ...).
you could save the prefix in another column, effectively allowing you to filter on it.
if the number in itself is unique I would use that as primary key, however if the numbers are only unique in the prefix itself, I would create a seperate sequence for the primary key and two columns "prefix" and "sequencenumber".
In addition, if you save in multiple columns this also allows more advanced sorting, grouping, counts, etc...
hope this helps.
best of luck.
|
|
|
|
|
Hi there,
I'm making a bible book app where I have listbox, richtextbox and search textbox.
I have som problem coding when the listbox text is chosen, It will show the listbox text + custom text in richtextbox.
I have done this:
private void btnAra_Click(object sender, EventArgs e)
{
int index = 0;
String temp = richTextBox1.Text;
richTextBox1.Text = "";
richTextBox1.Text = temp;
while (index < richTextBox1.Text.LastIndexOf(txtAra.Text))
{
richTextBox1.Find(txtAra.Text, index, richTextBox1.TextLength, RichTextBoxFinds.None);
richTextBox1.SelectionBackColor = Color.Orange;
index = richTextBox1.Text.IndexOf(txtAra.Text, index) + 1;
}
}
But since this is going to be a book app, I want the chosen listbox to show a text file in richtexbox and not only 2-3 sentences..
Any tip for what I can do?
Updated with this:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var str = listBox1.SelectedItem.ToString();
if (str == " Yaratılış Tevrat")
{
richTextBox1.Text = str + "\t\r\n\nText here";
}
else if (str == " Mısır'dan Çıkış (Yasa)")
{
richTextBox1.Text = str + "\t\r\n\ncustom text 2";
}
|
|
|
|
|
|
oPsType.FACId = TxtFACCrbf.Text;
oPsType.URC = TxtURCCrbf.Text;
oPsType.PPIDFrom = ddlfromppidcbrf.SelectedValue;
oPsType.PPIDTo = ddltoppidcbrf.SelectedValue;
foreach (ListItem item in lblMultiSelect.Items)
{
if (item.Selected)
oPsType.PAY_TYPE = oPsType.PAY_TYPE + item.Value.ToString();
<pre>
}
PSTYPE[] l = (from PSTYPE thenum in tmppsType
where thenum.URCName.Contains(oPsType.URC)
&& thenum.FACId.Contains(oPsType.FACId)
&& thenum.PAY_TYPE.Contains(oPsType.PAY_TYPE)
select thenum).ToArray();
PSTypeCollection x = new PSTypeCollection();
x.AddRange(l);
this.GridViewCRBF.DataSource = x;</pre>
|
|
|
|