|
I have the RichTextBox. And I was wondering how would I be able to how the user to place a table into the RichTextBox?
|
|
|
|
|
Hello everyone,
I need some idea since I am running out of my own and haven't been able to get it working.
I have a file called temp.txt which hold temparary data and will be deleted at the end of the Windows Application life. I have another file called perm.txt which is similar to the temp.txt file but it hold the saved data.
In order to avoid multipler data registration I would like to check to see if a particular data from temp.txt file has already been registered or not. If it hasn't then I will go ahead to save/register it into save.txt file. That is if the user choses to Save its temp.txt content by clicking on the SAVE button.
Any suggestion in this issue will be greatdly appriciated. Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
post the code if you want some help
|
|
|
|
|
I don't quite understand the problem/question.
As I understand the situation:
You save data in a temporary file which is deleted when the application exits.
There is another permanent file where the data in the temporary file is written/moved as long at the data doesn't already exist in the permanent file.
This would require your code to perform the following:
Read a record from the temporary file.
Read the contents of the permanent file searching for a matching record.
If no record is found in the permanent file, append the permantent file with the new record.
Depending on the size of the files and number of records, you may be able to read both files into memory when making comparisons and after any additions, simply write out a new permanent file from the records in memory.
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog
|
|
|
|
|
In addition to what Wayne Phipps said, I'd suggest that you store the records as Hash codes in a HashTable. This way you can compare small integers instead of large records, which could boost your performance dramatically.
Regards
|
|
|
|
|
Hi there, ive kind of an issue.... my prob is that im using a TCPListener in a class named Soctek_Server, and i have a form1, so i put a timer on the form in order that the code on the class keep executing, my prob is that only when a client made a request my form1 refresh its content, but until that happend all the form, the visual thing stays in white, all the application stays in a queue... it paralize, what i need to do , is make something with threads, to put the TCP listener in a thread independet of the form that way i could work whit the form.... not mattering if the TCPlistener is active or not. if someone can help me ..... plz
Ive been trying something with threads with the function "pintar" but it doesnt work, the form still paralize when the timer is running....
Here is the code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Test
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private IContainer components;
private System.Windows.Forms.Button cmdserver;
private System.Windows.Forms.Button cmdclient;
public Socket_Server server;
private System.Windows.Forms.TextBox txtmsg;
private System.Windows.Forms.Label label1;
public Socket_Client client;
private Timer timer1;
System.Threading.Thread myThread;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
server= new Socket_Server();
client = new Socket_Client();
myThread = new System.Threading.Thread(new System.Threading.ThreadStart(pintar));
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.cmdserver = new System.Windows.Forms.Button();
this.cmdclient = new System.Windows.Forms.Button();
this.txtmsg = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// cmdserver
//
this.cmdserver.Location = new System.Drawing.Point(216, 120);
this.cmdserver.Name = "cmdserver";
this.cmdserver.Size = new System.Drawing.Size(75, 23);
this.cmdserver.TabIndex = 0;
this.cmdserver.Text = "Servidor";
this.cmdserver.Click += new System.EventHandler(this.cmdserver_Click);
//
// cmdclient
//
this.cmdclient.Location = new System.Drawing.Point(216, 176);
this.cmdclient.Name = "cmdclient";
this.cmdclient.Size = new System.Drawing.Size(75, 23);
this.cmdclient.TabIndex = 1;
this.cmdclient.Text = "Cliente";
this.cmdclient.Click += new System.EventHandler(this.cmdclient_Click);
//
// txtmsg
//
this.txtmsg.AcceptsReturn = true;
this.txtmsg.Location = new System.Drawing.Point(216, 84);
this.txtmsg.Name = "txtmsg";
this.txtmsg.Size = new System.Drawing.Size(280, 20);
this.txtmsg.TabIndex = 2;
this.txtmsg.Text = "txtmsg";
this.txtmsg.TextChanged += new System.EventHandler(this.txtmsg_TextChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(216, 248);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 23);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(512, 342);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtmsg);
this.Controls.Add(this.cmdclient);
this.Controls.Add(this.cmdserver);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
//System.Threading.Thread myThread;
//myThread = new System.Threading.Thread(new System.Threading.ThreadStart(Test.Form1.Main));
//myThread.Start();
}
private void Form1_Load(object sender, System.EventArgs e)
{
Test.Socket_Server.CreateLabel(this);
}
private void cmdserver_Click(object sender, System.EventArgs e)
{
label1.Text = "ENTRANDO A SERVER";
server.Begin();
}
private void cmdclient_Click(object sender, System.EventArgs e)
{
myThread.Start();
}
private void txtmsg_TextChanged(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = true;
label1.Text = timer1.Interval.ToString();
server.Begin();
//myThread.Start();
}
public void pintar()
{
label1.Text = "entre al thread";
//myThread.Suspend();
}
}
}
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Globalization;
namespace Test
{
///
/// Summary description for Socket.
///
///
public class Socket_Server
{
private static Label label;
public Socket_Server()
{
//
// TODO: Add constructor logic here
//
}
public static void CreateLabel(Control Form1)
{
label=new Label();
label.Height=400;
label.Width=200;
label.Location = new Point(10,10);
label.Enabled = false;
label.Visible=true;
Form1.Controls.Add(label);
}
public void Begin()
{
try
{
IPAddress ipAd = IPAddress.Parse("148.210.182.80");
// use local m/c IP address, and
// use the same in the client
/* Initializes the Listener */
TcpListener myList=new TcpListener(ipAd,8002);
/* Start Listeneting at the specified port */
myList.Start();
label.Text=label.Text+"/r"+("The server is running at port 8001...");
label.Text=label.Text+"\r"+("The local End point is :" +
myList.LocalEndpoint );
label.Text=label.Text+"\r"+("Waiting for a connection.....");
Socket s=myList.AcceptSocket();
label.Text=label.Text+"\r"+("Connection accepted from " + s.RemoteEndPoint);
byte[] b=new byte[100];
int k=s.Receive(b);
Console.WriteLine("Recieved...");
for (int i=0;i
|
|
|
|
|
I am currently having dificulties in understanding your problem. Please be a little more specific and maybe I can help you...
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
ok the thing is that , i need a sort of thread that make aable to run a tcplistener and the form, ive been reading some articles of threads but i cant understand them very well...
so the thing is, when I run the TCPListener all the buttons, an things on the form freeze cause the myList.Start() (on the class Socket_Server) is activated so the hole application is waiting for a request froma client (another program that send a string).... so, i need that this process of being waitng or listening for some client be on the background, or parallel to all the action of the form... i put the code of the form , and the class in where is the TCPlistener, i call that class by an object of the class. one way i tried was with a timer on the form, that it... cycles (loops) the code on the class so i can recive a bunch of request for clients, another way is with a button that wen is clicked listen for a client til some client requests.. ..
so ... thats it... i need that the listener can be always on, grabbing the information that the clients send and be able to storage that info, and at the same time that i can work with my form normaly, looking like the process of waiting for clients be trasnparent
|
|
|
|
|
Hi,
u can make a Background task by using class
BackGroundWorker
check the help (i hope this help u)
Egyptian Generator
|
|
|
|
|
Ok, now I think I understood your problem...
So your application freazes when you want to handle data (establish a connection, send/recide data).
The problem can be solved by using threads but noy how you tried...
The server instance (class instance) should process any data in aseparate thread, not the application thread,or yourapplication freazes...
Imagine you start a thread that once a 10 secs changes the text of a label. But if your form is on a thread that is waiting for an opperation to finnish the label won't be changed because the forms thread won't be able to run the text changing code invoked by the "10 secs" thread.
So try to use the your "server" class in a separate thread. And if I am right than the function you call there freazes the client (thread) until a connection is available...
Hope this clarifies your problem....
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
ok, that is what ive been trying... but i cant reach... look.... i already post my first code... i tried some other things like this
private void Form1_Load(object sender, System.EventArgs e)
{
Test.Socket_Server.CreateLabel(this);
System.Timers.Timer reloj = new System.Timers.Timer();
reloj.Enabled = true;
reloj.Interval = 1000;
reloj.Elapsed += new System.Timers.ElapsedEventHandler(reloj_Elapsed);
}
public void pintar()
{
//label1.Text = "voy a entrar del thread";
Socket_Server servi;
servi = new Socket_Server();
servi.Begin();
}
private void reloj_Elapsed(object sender, EventArgs e)
{
Socket_Server servi;
servi = new Socket_Server();
servi.Begin();
//Thread hilo = new Thread(new ThreadStart(pintar));
//hilo.IsBackground = true;
//hilo.Start();
}
as u can see i tried with a timer, and also with threads it seems like now the thread for the class Server (or the tcplistener) is running on the background... but... i cant make that the client send me his data..... its seems like the timer is ... looping... the thread... and itried alredy decrese the interval but nothing...
there is also a code in comment cause i tried just with the thread instead of the timer... but nothing... let me post all of the code... form, server class and client class...
Form*************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace Test
{
///
/// Summary description for Form1.
///
///
public class Form1 : System.Windows.Forms.Form
{
private IContainer components;
private System.Windows.Forms.Button cmdserver;
private System.Windows.Forms.Button cmdclient;
public Socket_Server server;
private System.Windows.Forms.TextBox txtmsg;
private System.Windows.Forms.Label label1;
public Thread hilo;
public System.Threading.Timer reloj;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
server = new Socket_Server();
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.cmdserver = new System.Windows.Forms.Button();
this.cmdclient = new System.Windows.Forms.Button();
this.txtmsg = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// cmdserver
//
this.cmdserver.Location = new System.Drawing.Point(216, 120);
this.cmdserver.Name = "cmdserver";
this.cmdserver.Size = new System.Drawing.Size(75, 23);
this.cmdserver.TabIndex = 0;
this.cmdserver.Text = "Servidor";
this.cmdserver.Click += new System.EventHandler(this.cmdserver_Click);
//
// cmdclient
//
this.cmdclient.Location = new System.Drawing.Point(216, 176);
this.cmdclient.Name = "cmdclient";
this.cmdclient.Size = new System.Drawing.Size(75, 23);
this.cmdclient.TabIndex = 1;
this.cmdclient.Text = "Cliente";
this.cmdclient.Click += new System.EventHandler(this.cmdclient_Click);
//
// txtmsg
//
this.txtmsg.AcceptsReturn = true;
this.txtmsg.Location = new System.Drawing.Point(216, 84);
this.txtmsg.Name = "txtmsg";
this.txtmsg.Size = new System.Drawing.Size(280, 20);
this.txtmsg.TabIndex = 2;
this.txtmsg.Text = "txtmsg";
this.txtmsg.TextChanged += new System.EventHandler(this.txtmsg_TextChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(213, 215);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(283, 102);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(512, 342);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtmsg);
this.Controls.Add(this.cmdclient);
this.Controls.Add(this.cmdserver);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
Test.Socket_Server.CreateLabel(this);
System.Timers.Timer reloj = new System.Timers.Timer();
reloj.Enabled = true;
reloj.Interval = 1000;
reloj.Elapsed += new System.Timers.ElapsedEventHandler(reloj_Elapsed);
}
private void cmdserver_Click(object sender, System.EventArgs e)
{
label1.Text = "ENTRANDO A SERVER";
server.Begin();
}
private void cmdclient_Click(object sender, System.EventArgs e)
{
}
private void txtmsg_TextChanged(object sender, EventArgs e)
{
}
public void pintar()
{
//label1.Text = "voy a entrar del thread";
Socket_Server servi;
servi = new Socket_Server();
servi.Begin();
}
private void reloj_Elapsed(object sender, EventArgs e)
{
Socket_Server servi;
servi = new Socket_Server();
servi.Begin();
//Thread hilo = new Thread(new ThreadStart(pintar));
//hilo.IsBackground = true;
//hilo.Start();
}
}
}
Server Class ***********
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Globalization;
namespace Test
{
///
/// Summary description for Socket.
///
///
public class Socket_Server
{
private static Label label;
public Socket_Server()
{
//
// TODO: Add constructor logic here
//
}
public static void CreateLabel(Control Form1)
{
label=new Label();
label.Height=400;
label.Width=200;
label.Location = new Point(10,10);
label.Enabled = false;
label.Visible=true;
Form1.Controls.Add(label);
}
public void Begin()
{
try
{
IPAddress ipAd = IPAddress.Parse("192.168.1.100");
// use local m/c IP address, and
// use the same in the client
/* Initializes the Listener */
TcpListener myList=new TcpListener(ipAd,8002);
/* Start Listeneting at the specified port */
myList.Start();
label.Text=label.Text+"\r"+("The server is running at port 8001...");
label.Text=label.Text+"\r"+("The local End point is :" +
myList.LocalEndpoint );
label.Text=label.Text+"\r"+("Waiting for a connection.....");
Socket s=myList.AcceptSocket();
label.Text=label.Text+"\r"+("Connection accepted from " + s.RemoteEndPoint);
byte[] b=new byte[100];
int k=s.Receive(b);
label.Text=label.Text+"\r"+("Recieved...");
for (int i=0;i<k;i++)
label.text="label.Text+(Convert.ToChar(b[i]));
" asciiencoding="" asen="new" asciiencoding();
="" s.send(asen.getbytes("the="" string="" was="" recieved="" by="" the="" server."));
="" acknowledgement");
="" *="" clean="" up=""
="" s.close();
="" mylist.stop();
="" }
="" catch="" (exception="" e)="" {
="" "="" +="" e.stacktrace);
="" }
}
client="" class***********
using="" system;
using="" system.text;
using="" system.net;
using="" system.net.sockets;
using="" system.io;
using="" system.collections;
using="" system.drawing;
using="" system.componentmodel;
using="" system.windows.forms;
using="" system.data;
using="" system.globalization;
namespace="" test_ii
{
="" <summary="">
/// Summary description for Socket_Client.
///
public class Socket_Client
{
private static Label label;
public Socket_Client()
{
//
// TODO: Add constructor logic here
//
}
public static void CreateLabel(Control Form1)
{
label=new Label();
label.Height=400;
label.Width=200;
label.Location = new Point(10,10);
label.Enabled = false;
label.Visible=true;
label.AutoEllipsis = true; ;
Form1.Controls.Add(label);
}
public void Begin()
{
try
{
TcpClient tcpclnt = new TcpClient();
label.Text=label.Text+"\r"+("Connecting.....");
tcpclnt.Connect("192.168.1.100", 8002);
// use the ipaddress as in the server program
label.Text=label.Text+"\r"+("Connected");
label.Text=label.Text+"\r"+("Enter the string to be transmitted : ");
String str="KE ONGON";//Console.ReadLine();
Stream stm = tcpclnt.GetStream();
ASCIIEncoding asen= new ASCIIEncoding();
byte[] ba=asen.GetBytes(str);
label.Text=label.Text+"\r"+("Transmitting.....");
stm.Write(ba,0,ba.Length);
byte[] bb=new byte[100];
int k=stm.Read(bb,0,100);
for (int i=0;i
|
|
|
|
|
Your freezing roblem arises from the Socket_Server.Begin() on the line Socket s=myList.AcceptSocket();
If you would have rode msdn for adtitional info about AcceptSocket[^] you would have realised that "AcceptSocket is a blocking method".
So in ordrer to avoid the client form from hanging you can use the Pending method that verifies if a client is present (method that does not block the thread), or simply move the whole code that blocks the form on a separate thread (call the procedure on a sperarate thread).
Good luck.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
hey guys,
can any body implement the code given in the article in the following link.it's urgent guys!!!!!!!!!!
it makes use of asp.net and web service extension also.
link:-http://www.datastronghold.com/security-articles/general-security-articles/steganography-hiding-data-in-images.html
|
|
|
|
|
You can dynamically create images in C#/ASP.NET. CAPTCHA does that right?
|
|
|
|
|
but i want that code to be implemented for project so that i can send data in image for security purpose
|
|
|
|
|
dhananjaysonar wrote: but i want that code to be implemented for project so that i can send data in image for security purpose
Please note that security through obscurity[^] (including steganography) is generally a bad idea unless you're absolutely forced into using it.
That said, there is a wonderful series of articles here on CP that walks you through steganographic techniques. They can be found here[^].
|
|
|
|
|
Vega02 wrote: Please note that security through obscurity[^] (including steganography) is generally a bad idea unless you're absolutely forced into using it.
Only if it is used on its own. As part of a suite of security measures it can be beneficial.
|
|
|
|
|
dhananjaysonar wrote: can any body implement the code given in the article
There are probably some people that are able to implement this. The real question is: what are you willing to pay them for doing it or do you think someone will spent his freetime for doing your work.?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi all,
I want to call a function with string[] using invoke method, but compiler gives an error message "Parameter count mismatch." When I try to invoke a function with int[], there is no problem. Any suggestion? Here is the code;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public delegate void TbWrite(string[] eMessage);
public TbWrite writeTb=null;
public Form1()
{
writeTb = new TbWrite(TbCallBack);
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] veri = new string[] { "data1", "data2" };
this.BeginInvoke(writeTb, veri);
}
public void TbCallBack(string[] mData)
{
textBox1.Text = mData[0];
textBox2.Text = mData[1];
}
}
}
Regards.
Cengiz EKEN
|
|
|
|
|
Check out the signature for Control.BeginInvoke Method (Delegate, Object[])[^]. Notice the second parameter. It's modified with the params keyword, which means that you can pass zero to many parameters in addition to the delegate.
(actually, if you don't pass any additional arguments to BeginInvoke , I'm assuming that Control.BeginInvoke Method (Delegate)[^] is called instead.)
So when you want to pass an array of strings to BeginInvoke , do this:
this.BeginInvoke(writeTb, new object { veri });
This makes the entire string array a single argument that can be passed to your callback method.
Now, why does the integer array work when the string array does not? I think it has to do with the string array being an array of reference types. The BeginInvoke method is seperating out, for lack of a better word, each element of the array and treating them as seperate objects instead of treating the array as a single object.
So the compiler is interpretting the call to BeginInvoke as:
this.BeginInvoke(writeTb, "data1", "data2");
Two parameters are getting passed to your callback instead of one, which is where the mismatch exception is being thrown.
I'm guessing that the reason that the integer array doesn't have the problem is that the compiler is treating it as one object.
|
|
|
|
|
Thank you for your explanatory answer, it wat too useful to understand the error, but there still some point. Here is the new question regarding this
When I changed the code as follows, it gives again the same error
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public delegate void TbWrite(object [] eMessage);
public TbWrite writeTb = null;
public Form1()
{
writeTb = new TbWrite(TbCallBack);
InitializeComponent();
}
public void TbCallBack(object [] mData)
{
textBox1.Text = mData.GetValue(0).ToString();
textBox2.Text = mData.GetValue(1).ToString();
}
private void button1_Click(object sender, EventArgs e)
{
object[] veri = new object[] { "data1", "data2" };
this.BeginInvoke(writeTb, veri );
}
}
}
|
|
|
|
|
ceken wrote: object[] veri = new object[] { "data1", "data2" };
This gives you a problem for the same reasons I described in my previous post. You need to wrap your array inside an object array so that it's treated as one object:
string[] veri = { "data1", "data2" };
this.BeginInvoke(writeTb, new object { ver });
The string array is placed in an object array. The object array being passed to BeginInvoke only has one element, so it matches the parameter count of your callback when it passes that element to it.
|
|
|
|
|
Hi all,
I'm looking for a way to call VS2005 Shared Addin functions from an external VS2005 application.
a) The functions defined in Addin need some special demands?
b) In application how to invoke the function?
Thanks
|
|
|
|
|
|
Hey,
Could someone please point me into the right direction as to what I'd need to use in order to retrieve the size of a file on the web, without downloading the whole thing.
Thanks
|
|
|
|
|