|
This answer might erk a few programmers here in Discussions, but I can recall having a moderate amount of success taking C++ code verbatim and pasting it as C# code in the C# code behind module I was working on, attempting a compile, THEN ACTUALLY working from the compiler error list to clear the syntax breaks while F2-ing the HELP tome.
'Might try this if you find no other solution ...
|
|
|
|
|
Code--- C#
strHTML = "<table id='table1'> <colgroup><col width='190'/></colgroup><tbody>";
for (int i = 0; i < objDs.Tables[0].Rows.Count; i++)
{
if (i <= 10)
{
strUniqueID = "a" + i;
strBGColor = "a" + i.ToString();
}
else
{
strUniqueID = "a" + i;
strBGColor = "a" + (i - 1);
}
strSubject = objDs.Tables[0].Rows[i]["SubjectName"].ToString();
iSubjectID = Convert.ToInt32(objDs.Tables[0].Rows[i]["Subjectid"]);
<pre>
strHTML = strHTML + "<tr><td class='dark'><div id='" + strUniqueID + "' class='drag clone " + strBGColor + "'>" + strSubject + "</div><input id='b_" + strUniqueID + "' class='" + strUniqueID + "' type='button' value='' onclick='report(" + strUniqueID + ")' title='Show only " + strSubject + "'/></td></tr>";
}
strHTML = strHTML + "<tr><td class='trash' title='Trash'>Trash</td></tr>";
strHTML = strHTML + "</tbody></table>";
left.InnerHtml = strHTML;</pre>
---OutPut
English Test P | Kunal | Kunwar | Maths | Maths Test | Raj | Trash |
|
|
|
|
|
And?
You didn't ask a question...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm underwater on this
I used this tutorial
A Pretty Good Splash Screen in C#[^]
In the CloseForm, the Splash screen doesn't fade out, or just close and go away
hmm? In VB, you just add it, and it works. I'm stumped here.
So in my FormSplash I wrote [partial example]
public FormSplash()
{
InitializeComponent();
this.Text = String.Format("About {0}", AssemblyTitle);
this.ApplicationTitle.Text = AssemblyProduct;
this.Version.Text = String.Format("Version {0}", AssemblyVersion);
this.Copyright.Text = AssemblyCopyright;
}
static public void ShowSplashScreen()
{
if (ms_frmSplash != null)
return;
ms_oThread = new Thread(new ThreadStart(FormSplash.ShowForm));
ms_oThread.IsBackground = true;
ms_oThread.SetApartmentState(ApartmentState.STA);
ms_oThread.Start();
while (ms_frmSplash == null || ms_frmSplash.IsHandleCreated == false)
{
System.Threading.Thread.Sleep(TIMER_INTERVAL);<br />
}
}
static public void ShowForm()
{
ms_frmSplash = new FormSplash();
Application.Run(ms_frmSplash);<br />
}
static public void CloseForm()
{
if (ms_frmSplash != null && ms_frmSplash.IsDisposed == false)
{
ms_frmSplash.m_dblOpacityIncrement = -ms_frmSplash.m_dblOpacityDecrement;
}
ms_oThread = null;
ms_frmSplash = null;
}
And in my program.cs I wrote
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
FormSplash.ShowSplashScreen();
FormSplash.CloseForm();
Application.Run(new FormMain());
}
|
|
|
|
|
Why don't you set this.Cose(); as the last line of the ShowSplashScreen() method?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
I got the can't do that because it was made on a different thread error. So I played around with it, but I think I need to scrape that idea and start again for the 4th time. It's on the back burner for now.
|
|
|
|
|
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?
|
|
|
|