|
Thank you tried it and that works!
Bill
|
|
|
|
|
Hi guys,
We have a C# Windows application, now user ask if we can enlarge the font size through the whole application. I wonder how should we accomplish it?
And one more, if we do so, do we end up massing around the layout?
Thanks,
|
|
|
|
|
You can recursively loop through the .Controls of the form (and all controls that are children of other controls) and set the .Font property of each. Should be easy.
This won't mess up the layout of the application (i.e. your buttons won't move) however, if the text is large enough some of it obviously won't be visible.
#include "witty_sig.h"
|
|
|
|
|
|
I'm getting to the point where I feel comfortable with remoting, but I've ran into a problem that has caused me to question my original design. Hopefully you guys can shed some light on this.
I need my server application to talk to all connected clients. Additionally, I need the clients to be able to talk to the server (i.e. 2 way communication here). I have a single MarshalByRef class called Messenger, used by both client and server, that does the talking and listening.
The way it worked was I had my server publish his Messenger instance (using RemotingServices.Marshal method). Any client who wanted to connect to the server would simply connect (using RemotingServices.Connect method) to the server's Messenger instance, then call theServerMessenger.Login method. This all works fine and dandy.
The problem is that the server needs to talk to the connected clients. I can use the above algorith (i.e. the client .Marshal his Messenger instance and have the server call methods on that), but in order for that to work, calling RemotingServices.Connect on that instance requires an IP address obviously, meaning this solution will work only for LANs. If the server was on a machine outside the network, this solution would fail because the clients don't have IP addresses visible outside the network.
Another thought I had was that the client could pass his Messenger object to the server when he connects. That seems to work until the server tries to call a method on that client's Messenger object, the server tells me an internal server error occurs.
So there is my problem. I'd appreciate any thoughts on this.
#include "witty_sig.h"
|
|
|
|
|
The clients really just need to provide an object which the server communicates (like callbacks). This, of course, has to be a remotable object, but you don't need to worry about connecting back to the client so long as you are using a channel that supports 2-way communication, like the TcpChannel . By the very nature of HTTP, this won't work (although there are elaborate ways to simulate 2-way communication using polling, and IIRC there's one on CodeProject).
Just find a decent .NET Remoting chat example. There's plenty available on the 'net and probably a few here on CodeProject as well. It's a pretty simple concept where the server stores the client object and communicates with it. Using sponsors and lifetime management effectively (see ILease and ISponsor interface documentation in the .NET Framework SDK), you could even remove clients from an internal IList (or whatever you want to use) when they disconnect (of course always do error-checking and remove the client in case they're not connected and their sponsor has not yet timed out).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So you're saying basically to use a TcpChannel. I've been doing this, and whenever the server tries to communicate with the client objct, the server throws an internal error.
However, this is only the case when the server is running outside the LAN, and the client running inside the LAN. So it appears to be a firewall issue, perhaps the ports are being blocked.
#include "witty_sig.h"
|
|
|
|
|
More than likely a firewall is the problem. Proxies can also be a problem, as we're dealing with right now (mostly certain makes of proxies).
If the client and/or server is NAT'd (Network Address Translation) - not just simply firewalled (since a firewall can protect a network of non-reserved IP address) - you definitely have a problem that you can't get around at all or easily. To be honest, that often stumps me.
Take MSN and Windows Messengers for example. They require that your firewall (and the other end, if necessary) uses UPnP to publish the external IP address. The firewall will still route traffic accordingly, but the server and/or client does need to know the firewall's address. This is one possible fix. You can find more information about UPnP on MSDN (I've worked with it a little, but probably won't be able to help you with that).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok that figures thanks. One more question
If the server is inside the LAN, clients outside the firewall could still access the server provided I've setup port forwarding on the firewall, right?
For instance, if the server is running on 10.10.10.10, and I've setup my firewall to forward traffic on port 4030 to 10.10.10.10, then code the following:
const string ipAddressOfFirewall = ...;
const int port = 4030;
RemotingServices.Connect(typeof(ILogin), string.Format("{0}:{1}/Login.rem", ipAddressOfFirewall, port);
This seems feasible, but I'd be shocked if it works. Is it possible?
#include "witty_sig.h"
|
|
|
|
|
Good question. I guess that depends on how the server is bound. If it uses a hostname as opposed to an IP address, it should work. Give it a try and let us know.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Much to my suprise, this actually worked. :yay: The initial server-to-client manipulation seems much slower (need to run more tests to be certain about that), but yeah, it actually works.
#include "witty_sig.h"
|
|
|
|
|
I want to insert a row in a table which has a PK in the first field. I make a INSERT and give parameters to the sql server for all fields except the id field which is set in the db as Autoincrement so i dont have to worry about.
ALL of this is working fine.
But now i want to work immediatly after the insert with the new id of this row, which was given to the row automaticly by the sql-server. My problem now is that i have no Idea how to get the id value into my code (sure I can make a select query questioning all the parameters which i still have from the insertcommand, and ask for the id but this way seems very complicated to me!!!)
So if any more experienced Programmer than me can help me, please!!!
10000 Thanks in advanced.
PS
Languages C#, ADO.Net, and Sql Server 2000
best regards helli
|
|
|
|
|
Typically, you add a SELECT statement after your INSERT statement when used with a SqlDataAdapter (fills a DataSet from a SQL Server database using Fill , or vice versa using Update ). This makes sure that your DataSet is filled with what SQL Server assigned to the PK field.
To include both an INSERT and SELECT, separate your statements with a semi-colon (;):
sqlDataAdapter1.InsertCommand = new SqlCommand(
"INSERT INTO MyTable Name VALUES (@Name); SELECT ID, Name FROM MyTable",
sqlConnection1);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I think you need to use "IDENTITY/IDENT_CURRENT or SCOPE_IDENTITY" method of SQL. But I don't know how you can use it. If you get full source code please let me know.
|
|
|
|
|
I've added a movieplayer to my application, using Interop.QuartzTypeLib.dll
First time I load and play a video it works fine, but when I reload or open a different video and play that, the picture is all scrambled, but the sound is OK
Anyone got an idè?
The code:
public void Play(string strVideoPath)
{
CleanUp();
m_objFilterGraph = new FilgraphManager();
m_objFilterGraph.RenderFile(strVideoPath);
m_objBasicAudio = m_objFilterGraph as IBasicAudio;
try
{
m_objVideoWindow = m_objFilterGraph as IVideoWindow;
m_objVideoWindow.Owner = (int) this.Handle;
m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
m_objVideoWindow.SetWindowPosition(this.ClientRectangle.Left,
this.ClientRectangle.Top,
this.ClientRectangle.Width,
this.ClientRectangle.Height);
}
catch (Exception)
{
m_objVideoWindow = null;
}
m_objMediaEvent = m_objFilterGraph as IMediaEvent;
m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0);
m_objMediaPosition = m_objFilterGraph as IMediaPosition;
m_objMediaControl = m_objFilterGraph as IMediaControl;
m_objMediaControl.Run();
m_CurrentStatus = MediaStatus.Running;
}
private void CleanUp()
{
if (m_objMediaControl != null)
m_objMediaControl.Stop();
m_CurrentStatus = MediaStatus.Stopped;
if (m_objMediaEventEx != null)
m_objMediaEventEx.SetNotifyWindow(0, 0, 0);
if (m_objVideoWindow != null)
{
m_objVideoWindow.Visible = 0;
m_objVideoWindow.Owner = 0;
}
if (m_objMediaControl != null) m_objMediaControl = null;
if (m_objMediaPosition != null) m_objMediaPosition = null;
if (m_objMediaEventEx != null) m_objMediaEventEx = null;
if (m_objMediaEvent != null) m_objMediaEvent = null;
if (m_objVideoWindow != null) m_objVideoWindow = null;
if (m_objBasicAudio != null) m_objBasicAudio = null;
if (m_objFilterGraph != null) m_objFilterGraph = null;
}
Thanks
Thomas
|
|
|
|
|
Ummm... I really don't know, because I've never used that library before, but it *might* be a problem with the library.
For multimedia, I use The multimedia code found at http://www.mentalis.org/. Try it out, they've got source in both VB.Net and C#.
Aaron Eldreth
TheCollective4.com
My Articles
While much is too strange to be believed,
Nothing is too strange to have happened.
- T. Hardy
|
|
|
|
|
For starters, don't just set the objects to null . Objects that encsapsulate native resources expose a Dispose method that cleans-up the unmanaged (and sometimes even the managed resources) when you call Dispose . Simply setting these objects to null will (if there are no other references) cause the objects to get garbage collected when the application is idle or when memory must be freed. The unmanaged resources will not be freed by the GC, which is why they're called "unmanaged". It's possible that some of these objects have alloc'd global memory or something similar that is being shared between videos, possibly leading to the corruption you've witnessed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It's seems that this code is working fine on another computer.
So it probably has to be something with my Grafic card,the driver, or some mitche mach with some of my codecs.
Thomas
|
|
|
|
|
In any case, you might want to take Heath's advice and modify your code so it's written properly. This is avoid any future problems you may have and eliminate your code as a possible cause of those problems.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I set up the datasource
myDataGrid.DataSource= myDataSet.Tables[0].DefaultView;
When I scroll the cursor to next row, datagrid updates the dataset. It's ok. But without doing it, datagrid doesn't update the dataset. myDataSet.Tables[0].Rows.Count is 0 and
myDataSet.Tables[0].DefaultView.Count is 1.
For example user can enter some data to datagrid then after closes the window. Datagrid doesn't affect the dataset row.
I need to say "save data" to datagrid. How can I do this?
Thanks
|
|
|
|
|
Try to accept the changes in your datasource.
((DataSet)(myDataGrid.DataSource)).AcceptChanges();
or simply DataSet1.AcceptChanges();
Anfernius
|
|
|
|
|
It doesn't work.
Because data is in the datagrid. Datagrid has to send the data to dataset
Thanks for your interest.
|
|
|
|
|
All that does is mark the rows as unchanged so that if you passed the DataSet to DataAdapter.Update , no rows would be updated in your database (or other data store).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This is just the way the DataGrid works (as well as other controls). The changes aren't commited until the control looses focus.
For a little bit more understanding, see the DataGridColumnStyle.Commit method documentation in the .NET Framework SDK.
If you want to force the text (or whatever) to be commited, then you could, for example, call DataGrid.EndEdit before your Form closing (like overriding the OnClosing method or handling the Closing event). See that method documentation in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks. EndEdit works fine.
|
|
|
|