|
Edit : I have tried Dictionary<string[,], Texture2D> _lookup but doesnt work
In xna I want to create a texture2D factory class so that I can grab preloaded textures on the fly without having to load them repeatedly.
I want something like
paddleTexture = GetData<Texture2D>(string foldername,string assetname)
for example:
GetData<Texture2D>("Sprite","paddle");
But I am having generic Dictionary troubles
I just cant seem to create its structure properly !
I have tried Dictionary<string ,Dictionary<string,Texture2D>> which is not what I want at all and I also load the data via a simple XML file:
<?xml version="1.0" encoding="utf-8"?>
<FileSystem>
<Folder Name="Sprite" Location = "Image/2D/Sprite">
<Texture Name ="paddle"></Texture>
<Texture Name ="ball"></Texture>
</Folder>
</FileSystem>
Can anyone help me with the structure of the generic Dictionary?
Thanks !
-- Modified Wednesday, August 4, 2010 7:51 PM
|
|
|
|
|
Just solved it Dictionary<string, int=""> and simply joined the folder and asset name into one string for the primary key
ie: lookup.Add(folder + assetname,texture);

|
|
|
|
|
I've been working on this one for two days, and I DON'T think it's a memory or disk-space problem.
I have a C# image-processing application that uses Win32 to do the graphics for speed. I restructured it so that different threads could work on different images in parallel (so far with just one thread), and got the above error message.
The Google entries for this problem all assume there are memory/disk space limitations, but I know this isn't the problem because the old (non-threaded) version runs fine, and Process Explorer tells me the threaded version isn't using any more memory.
Has anyone seen this error message before? Any suggestions what to look for to track down the cause of this error?
Thanks,
Alan
|
|
|
|
|
Have you seen this blog[^]. Could it help in your situation?
|
|
|
|
|
The cause of the problem is that apparently Win32 bitmap handles become STALE, i.e. they're for temporary use only.
This led to the problem showing up in different places, depending on when Windoze decided to make the handles invalid.
The solution was to pass bitmaps into the lower-level C# functions, then obtain the handles at the last possible moment, inside a loop, just before descending into Win32. These handles were fresh for each iteration, and worked perfectly.
I think the Win32 system should provide a less-misleading error message when a stale handle has been used. &*($! Microsoft!
|
|
|
|
|
OK i have made a DLL with only one accessible function. It returns a panel with a label in it.
In the dll there's also an event handler for mousemouve. It needs to change the label to display the mouse position on the panel.
My problem is that i need everything done on the side of the DLL. The main program is only there to place the panel on a form and must not deal with event handling from the panel.
here's what i got for the dll
namespace PanelClass
{
public class ConstPanel
{
public Panel FabPan(int x, int y)
{
Panel P = new Panel();
Label L = new Label();
L.Left = 1;
L.Top = 1;
L.Text = "allo";
P.Height = y;
P.Width = x;
P.BorderStyle = BorderStyle.FixedSingle;
P.Controls.Add(L);
P.MouseMove += new MouseEventHandler(P_MouseMove);
return P;
}
void P_MouseMove(object sender, MouseEventArgs e)
{
//needs to change the text in label L
}
}
}
and the main application
private void button1_Click(object sender, EventArgs e)
{
PanelClass.ConstPanel P = new ConstPanel();
Panel Pan = P.FabPan(100, 100,1);
this.Controls.Add(Pan);
}
So what should i do
thanks for your time
modified on Thursday, August 5, 2010 8:41 AM
|
|
|
|
|
Hi,
1.
this should not be a problem at all; you need to pass the label reference from FabPan() to P_MouseMove(). The easiest way to do that is by turning L into a class member instead of a local variable.
2.
please use PRE tags (e.g. through the "code block" widget) to publish multi-line code snippets. The result is much more readable.
3.
I'm pretty sure your code does not compile as it is. Here are some reasons:
- there seems to be something wrong with the parameter list of PanFab().
- I don't think you can set a BorderStyle for a Panel.
4.
I have lots of comments on your coding style; frankly it is horrible. Here are some points that you should fix:
- having "class", "object" and many more as part of an identifier/name isn't a good idea, as it is either redundant or confusing (e.g. your PanelClass isn't a class, it's a namespace!)
- you should choose better variable names in general, e.g. having both Pan and P is confusing (and local variables by convention aren't TitleCased in C#)
- you should consider making ConstPanel inherit from Panel, and putting everything FabPan does into the constructor. You could still pass parameters to the constructor, however there are some advantages not doing that, besides a Panel has standard properties such as Size, Width, Height, and many more. So I suggest something like:
public class ConstPanel : Panel {
private Label label;
public ConstPanel() {
label = new Label();
label.Left = 1;
label.Top = 1;
label.Text = "allo";
...
That way, the button click handler would become:
Height) are public properties; you could turn it into:
private void button1_Click(object sender, EventArgs e) {
ConstPanel panel = new ConstPanel();
panel.Size=new Size(100,100);
this.Controls.Add(panel);
}
As it seems you are very new to all this, I strongly suggest you buy an introductory book on C# and study it. Experimentation is useful, having a book providing solid fundamentals is essential.
|
|
|
|
|
I need to split string "abcdef" in 2 groups - first will contain first 4 characters, second - remaining 2.
If I use this:
string[] w = Regex.Split("abcdef", "(?<first>.{4})(?<last>.{2})");
array w[] will contain 4 strings: "", "abcd", "ef", ""
How should I modify pattern so that w[] only contains 2 strings - "abcd" and "ef"?
|
|
|
|
|
You would use substring and not regex.
|
|
|
|
|
I know how to use substring for this. Is this not possible to achieve using regex?
|
|
|
|
|
Does it have to use the split method of Regex or can it use any regex methods? You can downgrade to the 1.0 or 1.1 Framework since those parsed it that way.
If you want to drive a nail using a banana that's fine, but if you ask for help in doing so, don't be surprised if the answer is either "don't do that" or "go ask a monkey".
|
|
|
|
|
Why would you use a regex for this? Why not just use a substring? How is it supposed to act for strings that aren't 6 characters exactly?
|
|
|
|
|
Actual goal is to split fixed-width string that consists of multiple fields (dozens of them). Fields are not delimited by any separator but defined by their positions in the string - first field occupies first 4 characters, second - next 2 characters, etc. Using regex allows to do this with one function call. As you can see I almost achieved what I am looking for - I just want to get rid of first and last string in the array that are empty. Yes, I can just ignore them in my code but I would like to know correct regex expression.
|
|
|
|
|
Will this serve your purpose?
string strSource = "abcdef";
string[] w = new string[] { strSource.Substring(0, 4), strSource.Substring(4) };
|
|
|
|
|
You should use Regex.Matches instead of Regex.Split. For example, take this input string:
11112233
When you apply this regex:
(?<first>.{4})(?=.{4})|(?<=.{4})(?<middle>.{2})(?=.{2})|(?<=.{6})(?<last>.{2})
You will get three results:
111
22
33
Note the regex has three sections, each separated by a pipe (|), which means "or". The first part:
(?<first>.{4})(?=.{4})
Finds any 4 characters that are followed by 4 characters. The middle part:
(?<=.{4})(?<middle>.{2})(?=.{2})
Finds any 2 characters that have 4 characters before them and 2 characters after them. The last part:
(?<=.{6})(?<last>.{2})
Finds any 2 characters that have 6 characters before them.
So, for the first match, you pad the end. For the middle matches, you pad the beginning and end. And for the last match, you pad the beginning. Not sure why you'd want to do this, but that's how it would be done. Performance may or may not be an issue... you'll have to test it with large strings. Also, if you use the regular expression more than once, make sure you use the compiled version (you can indicate a regex is compiled in the Regex constructor). Also, if you really are going to used groups, you could simplify the regex quite a bit:
(?<first>.{4})(?<middle>.{2})(?<last>.{2})
Then you can just get the sections by their group name (one match will be produced, but many groups will be in that match). And if you want to ignore certain sections of the string, you can do that too:
(?<first>.{4})(?<middle>.{2})(?<ignore>.{2})(?<last>.{2})(?<ignore>.{2})
Try that with this input string:
111122334455
And if you really want to use Regex.Split for some reason, something like this might work for the example you gave:
(?<=.{4})(?=.{2})
|
|
|
|
|
Thanks, just what I was looking for
|
|
|
|
|
Good Day
I have the following code
<br />
String XMLString = Convert_To_XML(Search);<br />
StringReader xmlSR = new StringReader(XMLString);<br />
xmlDatadoc.DataSet.WriteXml(XMLString);<br />
dsFinal = xmlDatadoc.DataSet;<br />
dsFinal.ReadXml(xmlSR);<br />
DataView dvSubjects = dsFinal.Tables[0].DefaultView;
when i run it , i get
Illegal characters in path.
it looks for a path and i am using an xml string, how to i add an xml from a string variable to a dataset
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Vuyiswa Maseko wrote: when i run it , i get
Illegal characters in path.
On which statement do you get this message, and what are the contents of the variables (strings) that the statement is operating on?
It's time for a new signature.
|
|
|
|
|
Good Day Richard
This is the line
<br />
xmlDatadoc.DataSet.WriteXml(XMLString);
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
MSDN[^]
"DataSet.WriteXml Method (String)
Writes the current data for the DataSet to the specified file.
"
In other words, it's expecting a filename, not an XML string.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi,
Am developing a winforms app using C#.
I am using binding source to design the forms.
I have a combobox with items "Yes" and "No"
depending on the selection of this I enable or disable a text box.
private void MyComboBox_TextChanged(object sender, EventArgs e)
{
if(MyComboBox.Text == "Yes")
{
textBox1.Enabled = true;
}
else
{
textox1.Text = "";
textbox1.Enabled = false;
}
}
Lets say I have selected "Yes" from the combobox and entered text into the textbox1 and save the input on save_click.
the value gets stored into the database.
Now if I go back to the form and edit it....I now change the combox to "NO". It clears the text in the textbox1 to "". When i click on save...it saves the record.
But the problem is that it is not updating it into the database.?
Any idea why this is happening or do i need to include more code into the event.
Help Appreciated..thanks,
|
|
|
|
|
You should be using the selected item changed event and not the Text Changed event. Also change your combo box to be of type DropDownList.
|
|
|
|
|
Can you tell me how to update the database when the binding source is modified please?
In this case the textBox text is being modified and I want to know how the selected item changed (i think ur trying to say SelectedIndexChanged event ?)
and changing the property of the combobox to dropdownlist would solve this issue?
Thanks,
|
|
|
|
|
Good morning.
Using Visual Studio 2008 (C# - Excel 2007 Add-in) I created a Excel 2007 Ribbon tab named Macros. It contains several buttons. I got some sample code online, but I can seem to run the macros. I have the following:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
private void btnImport_Click(object sender, RibbonControlEventArgs e)
{
object oMissing = System.Reflection.Missing.Value;
Excel.ApplicationClass oExcel = new Excel.ApplicationClass();
oExcel.Visible = true;
Excel.Workbooks oBooks = oExcel.Workbooks;
Excel._Workbook oBook = null;
oBook = oBooks.Open("c:\\Book1.xlsx", oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
RunMacro(oExcel, new Object[] { "Import" });
}
private void RunMacro(object oApp, object[] oRunArgs)
{
oApp.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, oApp, oRunArgs);
}
Any idea what might be an issue with the code? WHEELS
|
|
|
|
|
Update - I have the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
using System.Windows.Forms;
namespace ExcelAddInCustomTab
{
public partial class RibbonCustom : OfficeRibbon
{
public RibbonCustom()
{
InitializeComponent();
}
private void btnFileImport_Click(object sender, RibbonControlEventArgs e)
{
Excel.ApplicationClass oExcel = new Excel.ApplicationClass();
RunMacro(oExcel, new Object[] { "FileImport" });
}
private void RunMacro(object oApp, object[] oRunArgs)
{
try
{
oApp.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod,
null, oApp, oRunArgs);
}
catch (Exception ex)
{
MessageBox.Show(ex.InnerException.Message);
}
}
}
}
In the Excel 2007 spreadsheet, the Import tab shows up with the several buttons I set up. I am getting the following error: The macro may not be available in this workbook, or all macros may be disabled.
I checked all the trusted location and permission settings, and the add-in and macros are not disabled.
WHEELS
|
|
|
|
|