|
|
Hi, PozzaVecia,
There are two main reasons you might want to make a Form/Window flash: one is to indicate an error message, or something urgently requiring the user's attention. In that case you want to bring the Form to the front, to make sure it's visible. The usual practice, in that case, is to put up a modal Form/Window, which will automatically appear as the frontmost window, and block your application.
You can define a Form, with whatever you want on it, and use FormX.ShowDialog() to display it modally. In many cases, however, the built-in MessageBox facility is all you need to use. Both these objects will automatically become the frontmost window when they are shown.
The second case is when you want to indicate to the end-user that you want them to bring a Form to the front, that's not in front now. But, it's hard for me to see a real reason for doing that:
1. if the Window is covered over by other Windows, the user won't see it change color, or Flash.
Using FlashWindowEx will not make the Window the active window, and bring it frontmost, although the Window will appear to have changed status visually, from inactive to active. MSDN docs for 'FlashWindowEx:
"It does not change the active state of the window."
"When a window flashes, it appears to change from inactive to active status. An inactive caption bar changes to an active caption bar; an active caption bar changes to an inactive caption bar."
In summary:
1. yes, you can make a Window flash, either by using the FlashWindowEx api that Dave K. referred you to, or by writing code, as you mentioned, using a Timer.
2. imho, you should use a modal Form/Window whenever you absolutely must get the end-user's attention, are willing to block the application, and require a response from the user.
3. in most cases, the built-in modal MessageBox facility will give you, for "free," a choice of buttons, default action button, icon, etc.
DialogResult result = MessageBox.Show("Core Melt Down Imminent" ,"Chernobyl Emergency Alert !",MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button3);
switch (result.ToString())
{
case "Ignore":
MessageBox.Show("Ignorance is life as usual.");
break;
case "Abort":
MessageBox.Show("To abort is impossible, sorry.");
break;
case "Retry":
MessageBox.Show("Trying again is a waste of time.");
break;
} There are some articles here on CP that may be useful to you: [^].
yours, Bill
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
modified 18-May-13 10:10am.
|
|
|
|
|
very very useful!!!
thanks a lot
|
|
|
|
|
How can I read a the value of a column datatype Timestamp in my c# code?
I know that the timestamp is not a datetime in sql server.
I just want to read this to a byte array.
My code so far:
I have tried 3 variations and none of them even compile.
var myTimestamp = (byte)dr["TimeStamp"].ToString();
var myTimestamp = dr["TimeStamp"].ToString() as byte[];
var myTimestamp = dr["TimeStamp"].ToString();
I have googled and am unable to find it.
Pendin Approval
|
|
|
|
|
Maybe try System.Byte[] myTimestamp = (System.Byte[]) dr["TimeStamp"] ;
|
|
|
|
|
PIEBALDconsult wrote:
Maybe try
System.Byte[] myTimestamp = <br />
(System.Byte[]) dr["TimeStamp"] ;
Thank You. This has now been resolved.
Pendin Approval
|
|
|
|
|
Try reading it as a long.
|
|
|
|
|
That ain't gonna fly. (Unless maybe he casts it on the database side first.)
|
|
|
|
|
Hi to all.
I have a strange behaviour in a MDI project. I created a toolstrip with buttons in MDI parent for common operations in all children forms (New, Save and Delete).
In a child form, I have a DataGridView with a CheckBoxColumn and a TextBoxColumn with a list of options to choose by user. If i check some checkbox and I press the Save button in the toolstrip, I can't save any data: all the checkbox returns false value. But if i put a button in the child form and call the same void, all work very well.
Someone can answer why?
Here the code for button in MDI parent:
private void tsbtnSave_Click(object sender, EventArgs e)
{
if (this.ActiveMdiChild is Basic.AnalyzersCylinders) ((Basic.AnalyzersCylinders)this.ActiveMdiChild).Save();
}
Here the code to read the results:
public void Save()
{
foreach (DataGridViewRow dgRow in dgvAnalyzers.Rows)
{
if (dgRow.Cells["CheckedItem"].Value != null)
{
if ((bool)dgRow.Cells["CheckedItem"].Value)
{
}
else
{
}
}
}
}
And, obviously, the code for the button in Child form call the same Save() void.
|
|
|
|
|
If you put a breakpoint in the save routine and execute your application does it go to debug when you click on the save button?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Yes. In the save routine I see the checkedbox items values... but when I press the button in MDI parent, this values are always false, if I press the button in the child form, the values passes in the correct way.
|
|
|
|
|
Hello
Is there a way to extract some values from an XML node using the XmlPathNavigator ?
I need to extrat information from a XML file. I was first trying to use an XmlTextReader but the pure sequential access seeme a bit tedious to handle
So I was trying to use the XpathDocument
I use a XPathNavigator to browse each node of my document (see code below)
But for each product I just need to extract a few information
- Brand
- Model
- ID
(there are a lot of other unneeded information)
Is it possible to do that with the XpathNavigator ?
Or do I need another approach ?
Obviously I can write my own parser but I can't believe that there is no simple way with standard classes ?
Thanks for any help !
XPathDocument xmldoc = new XPathDocument(p);
XPathNavigator nav = xmldoc.CreateNavigator();
int j = 0;
foreach (XPathNavigator product in nav.Select("liste/mobile"))
{
j++;
}
|
|
|
|
|
Probably, but I've never used one. I use an XmlDocument; the SelectNodes and SelectSingleNode methods use XPath.
|
|
|
|
|
Thanks
I finaly found some solution
The first think to care is also the granularity
In my case every product embed a bloc_im node that contains everything
So the first select must be on "liste/product/bloc_im"
I was first doing "liste/product" and it take me a while to understand that first issue !
foreach (XPathNavigator product in nav.Select("liste/product/bloc_im"))
{
string refORF = product.SelectSingleNode("ref").Value;
string IdORF = product.SelectSingleNode("id").Value;
string Brand= product.SelectSingleNode("Brand").Value;
string modele = product.SelectSingleNode("model").Value;
sw.WriteLine("{0}\t{1}\t{2}\t{3}",Id,ref,Brand,modele);
XPathNavigator xNav = product.SelectSingleNode("TACS");
foreach (XPathNavigator xNav1 in xNav.Select("TAC"))
{
string Tac = xNav1.Value;
}
j++;
}
|
|
|
|
|
xmlDoc.SelectSingleNode(liste/mobile); should give the same results.
|
|
|
|
|
I've just discovered LINQ to XML, which makes processing XML files very easy.
You only need two classes (which become available when you have using System.Xml.Linq): XDocument and XElement.
XDocument opens the XML file. XElement is the type of each node in the XML tree. Some of the XElement methods return a nice IEnumerable list that you can process with foreach.
There's a lot more to LINQ to XML, but just these two classes enable you to easily do basic processing.
|
|
|
|
|
I'm not sure WCF is the way I should go here but I'm keen to get to learn a new technology so I thought I should investigate it at least.
We are developing a system in which we need a server-side application (with GUI, so not a Windows service) and several client side applications that communicate with this server side application. All of this happens on the internal network so I figured that TCP binding might be suitable.
The one approach would be to write some TCP/IP server routines on the server-side application and have the clients communicate with it over TCP sockets for which we'd have to implement certain messaging. What I dislike about this approach is the fact that all comms will be request-response type. In other words, the server can only send messages to the client if the client sent a message to the server.
So the possibility of full-duplex comms of WCF seems like a perfect solution. The thing I'm unsure of is whether WCF would allow for a server-side application that has a GUI and allows for user interaction.
I thought I might try getting to know WCF first by writing a small mini system, the sandwich lady notification system, consisting of a "server" side application which runs on the receptionist's computer. A number of other computers in the office then has a client application. The client application can send a message to the server application to subscribe itself to the notifications. When the sandwich lady arrives the receptionist can then open the GUI of the application on her machine and click a button which triggers the app to send a message to all the clients that has subscribed which in turn pops up a notification on the client machine.
I realise there might be better ways to achieve this particular solution but it is a reasonable analogy of what we ultimately want to achieve with out bigger system so I figure I might gain the skills I need if I can figure out how to write this little system.
My question is, could someone tell me please whether WCF is indeed the technology that should be used for this? I have only just started reading up on it but I am getting the impression that with WCF, the server side application will have to take the form of a service, not a desktop application. Could anyone give me some clarity on this please and possibly point me in the right direction for what I'm trying to achieve?
TIA
|
|
|
|
|
You might get a better response by posting your question in the WCF forum[^].
Use the best guess
|
|
|
|
|
Goodness! I didn't even notice there was a forum dedicated to WCF. Thanks for pointing out.
|
|
|
|
|
Hello,
I've just started to programm in C++, using Builder C++. I need to stablish comunication via internet between two computers. I've succed using the ClientSocket Component and the ClientServer but only if the computers are in a local network but not if the computers are in different networks. Here is my code for the server:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::BAbrirClick(TObject *Sender)
{
ServerSocket1->Port=StrToInt(Npuerto->Text);
ServerSocket1->Open();
BAbrir->Enabled=false;
BCerrar->Enabled=true;
BEstado->SimpleText="Servidor Conectado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = true;
}
void __fastcall TForm1::BCerrarClick(TObject *Sender)
{
ServerSocket1->Close();
BAbrir->Enabled=true;
BCerrar->Enabled=false;
BEstado->SimpleText="Servidor Cerrado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = false;
}
void __fastcall TForm1::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
BEstado->SimpleText="Conectado desde "+Socket->RemoteAddress;
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
}
void __fastcall TForm1::ServerSocket1ClientDisconnect(TObject *Sender,
TCustomWinSocket *Socket)
{
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections-1);
BEstado->SimpleText="Desconectado de "+Socket->RemoteAddress;
}
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
char * buffer;
int len;
AnsiString Mensaje;
int i;
int *tam;
tam = new int;
*tam = Socket->ReceiveLength();
len=Socket->ReceiveBuf(buffer,*tam);
buffer[len]=0;
TTime hora = TTime::CurrentTime();
AnsiString MensajeIn = Socket->RemoteAddress;
MensajeIn += " A las " + TimeToStr(hora) + " Dice" "----->";
ChatBox->Lines->Add(MensajeIn +StrPas(buffer));
BEstado->SimpleText=IntToStr(len)+"Nuevo mensaje entrante!";
Mensaje = StrPas(buffer);
strcpy(buffer,Mensaje.c_str());
for(i=0;i<ServerSocket1->Socket->ActiveConnections;i++)
ServerSocket1->Socket->Connections[i]->SendBuf(buffer,strlen(buffer));
delete[] buffer;
}
void __fastcall TForm1::BEnviarClick(TObject *Sender)
{
char buffer[256];
int i;
AnsiString Mensaje = CampoMensaje->Text;
strcpy(buffer,Mensaje.c_str());
for(i=0;i<ServerSocket1->Socket->ActiveConnections;i++)
ServerSocket1->Socket->Connections[i]->SendBuf(buffer,strlen(buffer));
TTime hora = TTime::CurrentTime();
ChatBox->Lines->Add("Servidor a las " +TimeToStr(hora)
+ " dice----->" + Mensaje);
}
void __fastcall TForm1::LimpiarClick(TObject *Sender)
{
ChatBox->Clear();
}
void __fastcall TForm1::CampoMensajeKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == 13)
TForm1::BEnviarClick(CampoMensaje);
}
void __fastcall TForm1::NpuertoKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == 13)
TForm1::BAbrirClick(Npuerto);
}
void __fastcall TForm1::TcpServer1Accept(TObject *Sender,
TCustomIpClient *ClientSocket)
{
TcpServer1->RemotePort = StrToInt(Npuerto->Text);
TcpServer1->Open();
BAbrir->Enabled=false;
BCerrar->Enabled=true;
BEstado->SimpleText="Servidor Conectado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = true;
}
void __fastcall TForm1::TcpServer1CreateHandle(TObject *Sender)
{
NOnline->Text=IntToStr(TcpServer1->Active-1);
BEstado->SimpleText="Desconectado de "+TcpServer1->LocalHostName();
}
How can I implement comunication (a simple chat is enough) between the two computers?
|
|
|
|
|
First of all, good job on starting out with C++. It can be a daunting task, but I've no doubt you'll rise to the challenge. I would like to point out, however, that this is the C# forum and not the C++[^] one. You'll have more luck getting an answer if you ask your question in the correct forum.
|
|
|
|
|
Oh my god, I'm so sorry, many hours without any break in front of the computer. Thanks for notify
|
|
|
|
|
We've all been there, there is even a phrase for it[^]
“Education is not the piling on of learning, information, data, facts, skills, or abilities - that's training or instruction - but is rather making visible what is hidden as a seed” “One of the greatest problems of our time is that many are schooled but few are educated”
Sir Thomas More (1478 – 1535)
|
|
|
|
|
Hello Experts,
I am working on an Excel application and I have input in the form of an HTML table string.I need to past this string in my excel work sheet.
Please let me know how can I do this?
Thanks,
Raesa
|
|
|
|
|
|