|
|
What is your context? Are you building a winforms application? an asp.net app? When you "load a reusable template" are you trying to support screen display? print output?
|
|
|
|
|
Sorry if I was too vague. For this instance I am trying to export a screenshot to a bmp file, but need to enter in some specifics about the selected object I am taking a screenshot of to the top the bmp. It will end up looking like a small report on top with an attached screenshot on the bottom.
I think there was hope of using this also in winforms, hence the ambiguity. I'm just having a bit of a mental road block visualizing using HTML vs. using GDI.
|
|
|
|
|
I want to take user input in a DataGridView. I am trying to adapt a code sequence I had from a text box input. I get the error "The name 'PRWEB1' does not exist in the current context". Below is a code sample I had before and next is what I am using now. Please help!
string AS1 = as1.Text;
string sAS1 = AS1.PadRight(AS1.Length + (as1.MaxInputLength - AS1.Length));
foreach (DataGridViewRow row in prweb1.DataGridView.Rows)
{
DataGridViewCell cell = row.Cells[0];
string PRWEB1 = cell.Value.ToString();
}
string sPRWEB1 = PRWEB1.PadRight(PRWEB1.Length + (prweb1.MaxInputLength- PRWEB1.Length));
|
|
|
|
|
You are declaring the variable PRWEB1 inside a loop. That is the only place it exists.
Change it to something like:
string PRWEB1 = string.Empty;
foreach (DataGridViewRow row in prweb1.DataGridView.Rows)
{
DataGridViewCell cell = row.Cells[0];
PRWEB1 = cell.Value.ToString();
}
string sPRWEB1 = PRWEB1.PadRight(PRWEB1.Length + (prweb1.MaxInputLength- PRWEB1.Length));
modified on Monday, July 27, 2009 5:46 PM
|
|
|
|
|
Hi -
I'm a hardware engineer doing my first little c# project and have gotten stuck.
In the code below, the compiler objects to the open and close parentheses in the last line where I do the .add . I get the same results if I just use the class instead of the instance.
I can't find much Google help on c# list adds except simple strings, and found nothing on a list of classes.
Help!
Chuck
public class CUserMem
{
public UInt32 bUsed; // supposed to be a Boolean but occupies 4 bytes
public UInt32 nCFreqHz; // Center Frequency
public UInt32 nDemIdx; // demod index: 4 or 5
public UInt32 nDemBWIdx; // normally 3 for 6 kHz
public UInt32 nVBFBWHz; // user selected filter BW (3.63 is a normal choice)
public int nVBFFcHz; // frequency offset of filter
public long aTime; // long (epoch time when memory was created)
public char version; // 0 currently
public char[] extDC; // 3 bytes of external downconverter info
public char [] rsvd; // 4 bytes reserved
public char [] desc; // memory tag
}
List <CUserMem> MemoryBank = new List<CUserMem>(10);
CUserMem TempCUserMem = new CUserMem();
MemoryBank.Add(TempCUserMem);
|
|
|
|
|
What error message are you getting?
Life goes very fast. Tomorrow, today is already yesterday.
modified on Friday, September 25, 2009 5:12 AM
|
|
|
|
|
Strange, your code compiles fine for me.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hmmm, maybe his code is exactly as he has put. I mean with the .Add line at class level. That would cause compile error, if I am not mistaken?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Ah, I think I may have it. Is the error:
Invalid token '(' in class, struct, or interface member declaration ?
If so, it's because you can't add to the list outside of a method.
Wrong:
public class MyClass
{
List<CUserMem> MemoryBank = new List<CUserMem>(10);
CUserMem TempCUserMem = new CUserMem();
MemoryBank.Add(TempCUserMem);
} Correct:
public class MyClass
{
List<CUserMem> MemoryBank = new List<CUserMem>(10);
public MyClass()
{
CUserMem TempCUserMem = new CUserMem();
AddToList(TempCUserMem);
}
void AddToList(CUserMem userMem)
{
MemoryBank.Add(userMem);
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Great Minds...
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Strange, we both reached the same conclusion at exactly the same time!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
You nailed it, Dave.
Thanks for the clear explanation and the code for doing it right. Many people wouldn't have added that. It helps a non c# person making the bigger-than-expected jump from straight c.
Chuck
|
|
|
|
|
No problem - glad to help
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
i work with sms and i want to convert my string to binary
this string is
encoded using the 16-bit UCS-2 character encoding
how i can do that;
i try code like comming and it not work
byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(s_unicode);
byte[] utf = System.Text.Encoding.Unicode.GetBytes(s_unicode);
byte[] utf1 = System.Text.Encoding.BigEndianUnicode.GetBytes(s_unicode);
|
|
|
|
|
|
Hi All,
I've been putting together a short program too automatically to find and replace a string within all files of a directory.
For my first set of replacements I want to replace:
• “>” with “>”
• “<” with “<”
Program.CS
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class Program
{
static void Main(string[] args)
{
string userDir = "C:\\xmlreformat";
try
{
string[] filePaths = Directory.GetFiles(userDir);
foreach (string i in filePaths)
{
Reformat.Replace(i);
}
Console.WriteLine("Operation Succeeded \n \n Press Any Key to Exit");
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine("Directory Not Found:" + e.Message);
Console.WriteLine("\n \n Press Any Key to Exit");
Console.ReadKey();
}
}
}
}
Reformat.CS
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class Reformat
{
public static void Replace(string FName)
{
StreamReader File = new StreamReader(FName);
string fileContent = File.ReadToEnd();
File.Close();
StreamWriter NewFile = new StreamWriter(FName);
string fileContentCopy = fileContent;
string istring1 = ">";
string ostring1 = ">";
string istring2 = "<";
string ostring2 = "<";
fileContentCopy.Replace(istring1, ostring1);
fileContentCopy.Replace(istring2, ostring2);
fileContent = fileContentCopy;
NewFile.Write(fileContent);
}
}
}
However when I run the program it doesnt seem to work at all. Any ideas?
Thanks, George
|
|
|
|
|
GrgBalden wrote: fileContentCopy.Replace(istring1, ostring1);
fileContentCopy.Replace(istring2, ostring2);
String.Replace function returns an altered string, it does not change the instance itself.
You need to use...
fileContentCopy = fileContentCopy.Replace(istring1, ostring1);
fileContentCopy = fileContentCopy.Replace(istring2, ostring2);
I would also like to add that reading a whole file to a string, in my opinion, is not a good thing. I would prefer to read a character at a time and match it to a set of keywords and replace any matches.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi, Thanks for the help
I've added your suggestion and it seems to be working; I'm now trying to change the file extention of the files in the directory from .txt to .xml
The text files already have the xml, i just need to change the file extention? Any ideas? I tried to impliment an Ext Changer class (last in the list) but doesnt seem to work?
Any provide any sample code?
Program.CS
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class Program
{
static void Main(string[] args)
{
string userDir = "C:\\xmlreformat";
try
{
string[] filePaths = Directory.GetFiles(userDir);
foreach (string i in filePaths)
{
Reformat.Replace(i);
}
Console.WriteLine("Operation Succeeded \n \n Press Any Key to Exit");
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine("Directory Not Found:" + e.Message);
Console.WriteLine("\n \n Press Any Key to Exit");
Console.ReadKey();
}
}
}
}
Reformat.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class Reformat
{
public static void Replace(string FName)
{
StreamReader File = new StreamReader(FName);
string fileContent = File.ReadToEnd();
File.Close();
StreamWriter NewFile = new StreamWriter(FName);
string fileContentCopy = fileContent;
string istring1 = ">";
string ostring1 = ">";
string istring2 = "<";
string ostring2 = "<";
fileContentCopy = fileContentCopy.Replace(istring1, ostring1);
fileContentCopy = fileContentCopy.Replace(istring2, ostring2);
fileContent = fileContentCopy;
NewFile.Write(fileContent);
NewFile.Close();
}
}
}
ExtChanger.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class ExtChanger
{
public static void WriteFileName(string userDir, string FName )
{
string NewFN = FName.Replace(".txt", ".XML");
Console.WriteLine(NewFN);
TextWriter tw = new StreamWriter(FName);
}
}
}
|
|
|
|
|
Try using the FileInfo class (in System.IO)...
FileInfo fi = new FileInfo("<FilePath>");
string NewFN = fi.Name.SubString(0, fi.Name.Length - fi.Extension.Length);
NewFN += ".XML";
fi.MoveTo(fi.DirectoryName + NewFN, true);
That should do the trick for you
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
System.Web.HttpUtility.HtmlEncode
and
System.Web.HttpUtility.HtmlDecode
|
|
|
|
|
Thanks for the pointer, I was hoping that someone would know how to change a file extention by changing the file extention using a string?
Any more ideas?
|
|
|
|
|
System.IO.Path.GetFileNameWithoutExtension
and
System.IO.File.Move
|
|
|
|
|
Hello,
I'm trying to make my form blink when it's minimaze or not in focus (like in MSN),
when some event fired.
Is there any option of doing it with C#?
Thanks
modified on Monday, July 27, 2009 12:40 PM
|
|
|
|
|
Have a look at this[^]. Especially the link within to this[^]
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|