|
i havetwo PCs one with resolution 800*600 and second Pc with resolution 1024*768 i have made a windowform where i place a groupbox full of controls the problem is this that when i run that application on 800*600 pixels PC the controls are displayed as the were placed on the form but when i run it on the PC with 1024*768 resolution the controls are squeezed on the form leavingl ot of space empty on the form how to over come this problem
sas
|
|
|
|
|
Set the dock and anchor properties of your controls so that it sizes properly
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Dear All,
Am having Nearly 470 Text files. I want to do a text replacement in all these files. There are 60-80 replacements in each page. here is sample contents of one of the file
<input type=hidden name="item" value="Kansas State Backpack"><br />
<input type=hidden name="Price" value="39.99"><br />
<input type=hidden name="PartNo" value="XXX-XX"><br />
<input type=submit value="Add to Cart"><br />
</form><br />
<p><a href="javascript:popUp('../images/Backpack/158-62.jpg')"><br />
<br />
<input type=hidden name="item" value="Oregon Backpack"><br />
<input type=hidden name="Price" value="39.99"><br />
<input type=hidden name="PartNo" value="XXX-XX"><br />
<input type=submit value="Add to Cart"><br />
</form><br />
<p><A HREF="javascript:popUp('../images/Backpack/194-62.jpg')"><br />
<br />
<input type=hidden name="item" value="Arizona Backpack"><br />
<input type=hidden name="Price" value="39.99"><br />
<input type=hidden name="PartNo" value="XXX-XX"><br />
<input type=submit value="Add to Cart"><br />
</form> <br />
<p><A HREF="javascript:popUp('../images/Backpack/106-62.jpg')">
Here for value XXX-XX it must be replaced with the .JPG file name which comes below.
I have Created a Desktop Application in C# to do this. its getting converted but the alignment changes happens for files.
Am doing it this way
1) Am Opening Text File
private const string FILE_TAG = "[FILE]";<br />
private const string FILENAME_TAG = "[NAME]";<br />
private const string FILE_FILTER = "Text files (*.txt)|*.txt|All files (*.*)|*.*";<br />
<br />
private bool m_bIncludeRelativePath = false;<br />
private bool m_bRecurseSubDirs = false;<br />
<br />
private string m_sFilePath = string.Empty;<br />
private string m_sSourcePath = string.Empty;<br />
private string m_sInputTemplate = string.Empty;<br />
string sPingPath = string.Empty;<br />
public TEXT_REPLACE()<br />
{<br />
InitializeComponent();<br />
}<br />
private string GetOpenFilePath()<br />
{<br />
string sFilePath = string.Empty;<br />
<br />
OpenFileDialog openFile = new OpenFileDialog();<br />
openFile.Title = "Open File";<br />
openFile.Filter = FILE_FILTER;<br />
<br />
if (openFile.ShowDialog() == DialogResult.OK)<br />
{<br />
sFilePath = openFile.FileName;<br />
sPingPath = openFile.FileName;<br />
}<br />
<br />
<br />
return sFilePath;<br />
}<br />
private string LoadFile(string sFilePath)<br />
{<br />
FileStream file = null;<br />
StreamReader sr = null;<br />
string sContents = string.Empty;<br />
try<br />
{<br />
if (sFilePath.Trim() == string.Empty)<br />
{<br />
sFilePath = GetOpenFilePath();<br />
if (sFilePath.Trim() == string.Empty)<br />
{<br />
return string.Empty;<br />
}<br />
<br />
}<br />
<br />
FileInfo fsi = new FileInfo(sFilePath);<br />
<br />
string sFullPath = fsi.FullName;<br />
<br />
file = new FileStream(sFullPath, FileMode.OpenOrCreate, FileAccess.Read);<br />
<br />
sr = new StreamReader(file);<br />
<br />
string s = sr.ReadToEnd();<br />
sContents = s;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show("LoadFile() Error: " + ex.Message, "LoadFile Error", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
finally<br />
{<br />
if (sr != null)<br />
sr.Close();<br />
<br />
if (file != null)<br />
file.Close();<br />
}<br />
<br />
return sContents;<br />
}<br />
private void btnOpenFile_Click(object sender, EventArgs e)<br />
{<br />
<br />
Convert(GetOpenFilePath());<br />
<br />
<br />
}
2) Converting It and putting to a richtextbox
public void Convert(string Pathstring)<br />
{<br />
bool change = false;<br />
<br />
StreamReader re = File.OpenText(Pathstring);<br />
string test = "";<br />
string input = null;<br />
while ((input = re.ReadLine()) != null)<br />
{<br />
<br />
<br />
if (input.Contains("XXX-XX"))<br />
{<br />
change = true;<br />
<br />
}<br />
if (change == true)<br />
{<br />
if (input.Contains(".jpg"))<br />
{<br />
if (test.Contains("XXX-XX"))<br />
{<br />
test = test.Replace("XXX-XX", GetFilename((input)));<br />
}<br />
}<br />
}<br />
<br />
test += input+"\r\n";<br />
}<br />
re.Close();<br />
richTextBox1.Text = test;<br />
}<br />
public string GetFilename(string line)<br />
{<br />
string filename="";<br />
string[] Arr = line.Split('/');<br />
for (int i = 0; i <= Arr.Length - 1; i++)<br />
{<br />
if (Arr[i].Contains(".jpg"))<br />
{<br />
filename = Arr[i].ToString();<br />
}<br />
}<br />
filename=filename.Substring(0,filename.IndexOf(".jpg"));<br />
return filename;<br />
}
3 Saving it
private string GetSaveFilePath(string sInitialPath, string sDefaultFileName)<br />
{<br />
string sFilePath = string.Empty;<br />
<br />
SaveFileDialog saveFile = new SaveFileDialog();<br />
saveFile.Title = "Save File";<br />
saveFile.Filter = FILE_FILTER;<br />
<br />
if ((sInitialPath != null) && (Directory.Exists(sInitialPath) == true))<br />
{<br />
saveFile.InitialDirectory = sInitialPath;<br />
}<br />
<br />
if ((sDefaultFileName != null) && (sDefaultFileName.Length > 0))<br />
{<br />
saveFile.FileName = sDefaultFileName;<br />
}<br />
<br />
if (saveFile.ShowDialog() == DialogResult.OK)<br />
{<br />
sFilePath = saveFile.FileName;<br />
}<br />
<br />
return sFilePath;<br />
}<br />
private void btnSaveFile_Click(object sender, EventArgs e)<br />
{<br />
TextBox txtActive = GetActiveTabTextBox();<br />
<br />
SaveFile(sPingPath, richTextBox1.Text);<br />
<br />
}
So right now while saving the file its alignment is getting changed like this
<input type=hidden name="item" value="Kansas State Backpack"><input type=hidden name="Price" value="39.99"><input type=hidden name="PartNo" value="XXX-XX"><br />
can someone please help me out to sort this issue.
Thnaks in advance
-- modified at 5:25 Sunday 7th October, 2007
|
|
|
|
|
I'm not sure I follow, but I'd use File.ReadAllText and File.WriteAllText ( or ReadAllLines/WriteAllLines ) to read/write the file. And if the changes are known, I'd just use string.Replace to do them.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
IMHO it's a single line of code:
File.WriteAllText(file, File.ReadAllText(file).Replace("XXX-XX", "(the .jpg)"));
A full program:
using System.IO;
namespace BLA {
static class Program{
static void Main(string[] files)
{
foreach(string file in files)
File.WriteAllText(file, File.ReadAllText(file).Replace("XXX-XX", "(the .jpg)"));
}}}
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
It wont work since the.jpg has to be taken dynamically, its writing same file name for all XXX-XX
|
|
|
|
|
i have made a small program i want to make a setupo f that i had also created login id so how to create a setup
sas
|
|
|
|
|
File > New Project > Setup & Deployment Project
But fortunately we have the nanny-state politicians who can step in to protect us poor stupid consumers, most of whom would not know a JVM from a frozen chicken. Bruce Pierson
|
|
|
|
|
|
hi all,
in my .net application i have my ui in one server and business logic in one server and database from another server,
how can i establish communicatin between these 3 servers
if i want to get dabase info into code behind how can i access the data
Could some one help me
Thanks
sri
|
|
|
|
|
Use ADO.NET to communicate between business logic and the database (it will handle the network traffic for you). If your UI and business logic are on different servers "Windows Communication Foundation" surprisingly enough can be used as a foundation to communicate between two Windows servers.
If you are stuck with the outdated 2.0 Framework you might have to use Remoting or old webservices for the communication instead. This pretty much forces you to make your own data transfer objects and other boring tasks.
You can also use DataSets to communicate from your business logic to the GUI - this allows you to reflect the database more or less unchanged in the GUI which greatly reduce development time for the "small" price of unmaintanable code. If you are a consultant who only needs to make sure there is a future revenue stream it might be the way to go. If you do use datasets, please make sure to put this in the subject of future code project posts so I won't open them by accident and get sick.
|
|
|
|
|
plz any one help i need code in c# for checking afile is exisisting if it exists display that file if does not exists create a file in any folder using c# its very urgent if any ine have htis in vb.net also u can give me thanks
|
|
|
|
|
If you need code, then it's lucky you know how to program isn't it? If not I can send you my consultancy fees - an "urgent" job on a Sunday oh boy oh boy this is going to cost you. Do you have a house you can sell, I'm not quite sure selling the car will do it?
1) Look at System.IO.File.Exists (static method), or alternative System.IO.FileInfo.Exists (member method on the FileInfo class)
2) Opening it is not clear enough. Do you want it to open with the standard registered program (so if it is a .doc file start Word) or display the data in your own program.
If you want to open with the registered program, look at System.Diagnostics.Process.Start (you can give it a path to the file and it will resolve the correct executable for you). If you need to display it yourself use the System.IO namespace to read file (FileStream/StreamReader/BinaryReader are classes you need to know), then build whatever GUI required on top of the data using whatever you require and are familier with: WinForm, ASP.NET, or WPF.
|
|
|
|
|
Check File class under IO .
"Well dude, There's Always Better Ways To Do Things.
BY
BAIJUMAX
|
|
|
|
|
ramyanaidu wrote: its very urgent
That is a very rude thing to say around here.
Your post is a simple one that a quick google search can do for you.
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
foreach (myobject value in copy){
...
copy.RemoveAt(copy.IndexOf(value));
...
}
The first iteration works okay, but when the loop starts again, it throws and InvalidOperationException.
Any thoughts as to how I can remove an element within the arraylist whilst still using the same list?
|
|
|
|
|
Hi,
I see two ways to get rid of it:
1.
use a second ArrayList:
1a. if only a few to remove, store the indices to be removed in another empty ArrayList,
then in a second loop, remove those (warning: indices change while removing, so best
do the second loop backwards)
1b. if most of them to be removed, start a new ArrayList and copy the items you want to
keep, then throw away the original ArrayList
OR
2.
don't use foreach, instead use a for loop that runs backwards (or compensate for the
indices changing when removing).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
humblepgmr wrote: foreach (myobject value in copy){
...
copy.RemoveAt(copy.IndexOf(value));
...
}
Hi there,
There was some information at Microsoft about this. You might consider checking out http://support.microsoft.com/kb/555972 to read about it. Looks like a workaround involves creating a copy of the collection within the foreach loop.
Good Luck!
You can't teach people to be lazy - either they have it, or they don't.
-Dagwood Bumbstead
|
|
|
|
|
humblepgmr wrote: aList.sort(); //this doesn't work
Obviously. The Sort method doesn't have any clue how to compare and sort your objects. So, you have to provide an IComparer[^] implementation to compare two of your objects and return the result of the compare.
|
|
|
|
|
Talking to yourself again?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I know. Workin' for the government is drives you to drink. You end up in a dark corner babbling to yourself like an idiot. It'll pass in a few short weeks.
|
|
|
|
|
I have an class defined as below. This class has an integer value assigned to it named initiative. For the purposes of this post this value can be from 1 to 3.
<br />
public class Unit : IComparable<br />
{<br />
....<br />
public int Initiative = ....;<br />
<br />
public int CompareTo(object obj)<br />
{<br />
if (obj is Unit)<br />
{<br />
Unit u = (Unit)obj;<br />
return Initiative.CompareTo(u.Initiative);<br />
}<br />
throw new ArgumentException("object is not a Unit"); <br />
}<br />
}<br />
I have 10 of these objects defined in an array. I want to be able to sort the array by this initiative value however everytime I run a sort I want the object with equal value to be randomly organised. For example if I run sort once:
object - initiative
A - 1
B - 1
C - 1
D - 2
E - 2
F - 2
G - 3
H - 3
I - 3
J - 3
If I run it again, I may get:
object - initiative
B - 1
A - 1
C - 1
F - 2
D - 2
E - 2
G - 3
J - 3
H - 3
I - 3
How can I achieve this using IComparable?
Thanks in advance.
|
|
|
|
|
if (obj is Unit)
{
Unit u = (Unit)obj;
if (obj == this) return Random.Next(2) - 1;
return Initiative
someting like that
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: (obj == this)
This would compare references. Override == operator or write: (obj.Initiative == this.Initiative) .
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Sure - I was really just trying to show how to introduce some randomness. But thanks for adding this, it does make the overall answer more correct.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|