Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Megidolaon

@Megidolaon
About
Posts
192
Topics
50
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How do I transfer files over a local network?
    M Megidolaon

    Critique? I did not ask for critique, I asked for help. Which he pretended he gave, but actually did not give at all.

    C# sysadmin question help tutorial learning

  • How do I transfer files over a local network?
    M Megidolaon

    ...what? All you did is provide some vague comments that are unusable and post code that does exactly the same thing as mine.

    C# sysadmin question help tutorial learning

  • How do I transfer files over a local network?
    M Megidolaon

    I've tried a ton of tutorials but none work. Or rather, sooner or later ALL digress and leave the crucial part of transfering a file that isn't pure text. I'm remodeling an app I've previously used to transfer text and project specific objects over a LAN. I'm just having trouble to receive the file and save it again after the transfer (I assume the sending of the file is successful, but of course have no way to actually verify this). Here is the code for my client (sending) app:

        private void Send(string arg)
        {
            TcpClient client = new TcpClient(TB\_Host.Text, (int)UD\_Port.Value);
            FileStream fstream = File.Open(OFD\_File.FileName, FileMode.Open);
            NetworkStream nstream = client.GetStream();
            int data = 0;
    
            while (data > 0)
            {
                data = fstream.ReadByte();
                nstream.WriteByte((byte)data);
            }
    
            fstream.Close();
            nstream.Close();
            client.Close();
        }
    

    And this is the code for the server (receiving) app:

    public void Listen()
    {
    int port = 21112;
    byte[] result = new byte[1024];
    IPAddress address = IPAddress.Parse("127.0.0.1");
    TcpListener listener = new TcpListener(address, port);
    ipEnd = new IPEndPoint(address, port);
    listener.Start();
    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    int f = 0;
    object state = new object();
    socket.Connect(ipEnd);

            while (true)
            {
                TcpClient client = listener.AcceptTcpClient();
                NetworkStream ns = client.GetStream();
    
                f = socket.Receive(result);
                Invoke(new UpdateDisplayDelegate(UpdateDisplay), result);
            }
        }
    

    The current problem is that the code never reaches the invoke call (the Listen method is on a 2nd thread), which confuses me as there never had been any problem when I transferred text or objects. I tried a SoapFormatter, but while it works great for text and objects, I can't get it to work for files. I also tried using no sockets but a NetworkStream to write into the buffer:

    result = ns.Write(result, 0, int.MaxValue);

    but I always get an ArgumentOutOfRange exception for the size (I used int.MaxValue) parameter. Can you tell me how to

    C# sysadmin question help tutorial learning

  • "No connection could be made because the target machine actively refused it"
    M Megidolaon

    Thanks. I added a loop and now it works just fine.

    C# help

  • "No connection could be made because the target machine actively refused it"
    M Megidolaon

    I get this error when trying to send something between two apps over TCP. The weird part is that I can send one time without any trouble, but whenever I try a second time, I get this error. I use this code for the sending app:

    private void B_Send_Click(object sender, EventArgs e)
    {
    string send = "";
    send = TB_Quotes.Text;

            TcpClient tcp = new TcpClient(TB\_Host.Text, (int)UD\_Port.Value);
            NetworkStream ns = tcp.GetStream();
            StreamWriter writer = new StreamWriter(ns);
    
            writer.WriteLine(send);
            writer.Flush();
           
            ns.Close();
            writer.Close();
            tcp.Close();
        }
    

    And this code for the receiving app:

    public Form1()
    {
    InitializeComponent();
    Thread treceive = new Thread(new ThreadStart(Listen));
    treceive.Start();
    }

        public void Listen()
        {
            int port = 2112;
            string result = "";
            IPAddress localaddress = IPAddress.Parse("127.0.0.1");
            TcpListener listener = new TcpListener(localaddress, port);
            listener.Start();
            
            TcpClient client = listener.AcceptTcpClient();
            NetworkStream ns = client.GetStream();
            StreamReader reader = new StreamReader(ns);
            
            result = reader.ReadToEnd();
            Invoke(new UpdateDisplayDelegate(UpdateDisplay), new object\[\] {result});
        }
        public void UpdateDisplay(string text)
        {
            TB\_Quotes.Text = text;
        }
    

    I'm making sure the port is 2112 (if not, the first time would not be successful), but I don't understand why the 2nd time won't work. Thanks.

    C# help

  • syntax error in CONSTRAINT clause
    M Megidolaon

    I'm trying to use C# to add a column to an MS Access database, but I'm having trouble with the syntax. My SQL string amounts to something like this: ALTER TABLE t_customer ADD person_id integer CONSTRAINT FK_person_id FOREIGN KEY (person_id) REFERENCES t_person (person_id) I can't find any difference to the MSDN example syntax. Can you tell me where the error is? Thanks!

    Database database csharp help tutorial question

  • Best use of exception handling
    M Megidolaon

    :doh: :sigh: :(( In that order.

    The Weird and The Wonderful ruby

  • What tools do you use to design?
    M Megidolaon

    I end up using MS Paint for design actually. Don't laugh, I got used to it. Visio or other UML tools can end up eating a lot of time, so I first create quick & dirty designs with paint (copying and pasting makes it quite speedy) and if necessary translate that into fancy design with a real UML tool later.

    Design and Architecture design hosting cloud tools question

  • A questing about software design methodology
    M Megidolaon

    This is about the same for me. For personal projects I tend to change design even more often as there is no one else involved I first have to consult with. So, while coding I end up noticing a different approach might be better after all, etc. and change the structure. When I learned programming they certainly did hammer into my brain that it's imperative to create detailed design sheets beforehand, but from my experience you should never go too much into detail unless required client side as it makes you far to inflexible. And once you started changing designs, you should wait to change the documentation until the project is done or otherwise you end up wasting time to redo the documentation every time you change something. I think it's best to design a concept and basic classes/methods beforehand and then fill in the rest when you really have coded it to not end up documentation a program that never came to be.

    Design and Architecture design business help question

  • Hiding/Showing panels
    M Megidolaon

    Nah, it's not that much to do. But I tested it now with a form that has many controls for data input and it works like a charm. In the designer it's a huge form with all panels side by side for easy editing and the first thing I do when the form is constructed is change the size and hide all panels. Then I display the appropriate panel when selecting a node and hide all others.

    C# question

  • Hiding/Showing panels
    M Megidolaon

    Thanks. I didn't notice I had made panel2 the child of panel1 cause a single mm off and they were still independent. But changing locations works great. In the Visual Designer I have the panels next to each other and just overlay them at runtime like this:

    panel2.Location = new Point(panel1.Location.X, panel1.Location.Y);

    I still need to test how this works with the many different controls needed on other forms. After all the point of this is to switch from a huge cluster**** of nested tab controls to a more intuitive and easier usable design like for example VS options.

    C# question

  • Hiding/Showing panels
    M Megidolaon

    Apparently it didn't work because I had one panel over the other. But that is the entire point of this. Instead of putting a ton of controls next to each other or in TapControls, I want them to appear and disappear at the same location. How do I do that?

    C# question

  • Hiding/Showing panels
    M Megidolaon

    I try to hide/show panels with controls depending on what TreeView node the user clicks (for large data inputs), but it doesn't work and I have no idea why not. This is my code for the TreeView's AfterSelect event:

    private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
    {
    {
    if (treeView1.SelectedNode == null)
    {
    this.Text = "null";
    }
    else
    {
    if (treeView1.SelectedNode.Name == "Node1")
    {
    panel2.Visible = false;
    panel1.Visible = true;
    this.Text = "panel1 + | panel2 -";
    }
    else if (treeView1.SelectedNode.Name == "Node2")
    {
    panel1.Visible = false;
    panel2.Visible = true; //this does nothing?
    this.Text = "panel1 - | panel2 +";
    }
    }

            }
    

    By changing the form text I confirmed that the event gets properly thrown and by stepping through the code I found out that if Node2 is selected, the panel2.Visible = true line does absolutely nothing and afterwards Visible is still false. Why does that happen? I'm really confused. Thanks.

    C# question

  • TargetInvocationException?
    M Megidolaon

    Thanks. I guess I should better collect the data within the DoWork event and then report a while bunch at once. But now the TargetInvocationException is back and I can#t find it, no matter where I set a breakpoint.:confused:

    modified on Monday, August 16, 2010 9:47 PM

    C# data-structures help question

  • TargetInvocationException?
    M Megidolaon

    I told you what the exception is, VS doesn't give any further explanation (which is why I'm so confused). The code that throws it (according to VS) is the Application.Run line in the program class. Though seemingly I was able to get rid of it by properly checking the userstate and always sending new ArrayList. On the other hand, ReportProgress seems sorta broken. It happens once every blue moon compared to the DoWork event. In DoWork I'm running a loop and part of it is the ReportProgress method, yet the first time the event is actually raised happens between randomly the 350th and 400th time of the loop. How come? When debugging I set break points in the DoWork and ReportProgress events and confirmed that DoWork is only actually raised after DoWork looped several times.

    C# data-structures help question

  • TargetInvocationException?
    M Megidolaon

    So, it's been a while since I did any threading and so I thought to review some BackgroundWorkers. I made a test program and get this exception I cannot explain. It occurs during the ProgressChanged event when reading a double value. I'm using an ArrayList as argument where the first value is a double (for accurate progress report) and the second value is a string array. The exception gets thrown when trying to assign the value of the ArrayList to a local double variable. Can anyone tell me what went wrong and how I can fix it?

    private void BW_Text_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
    ArrayList arg = (ArrayList)e.UserState;
    double progress = (double)arg[0]; //exception gets thrown here
    string[] content = (string[])arg[1];

            textprogress += progress;
            TSL\_Text.Text = "Status: Reading..." + String.Format("{0:0.##}", textprogress) + "%";
    
            Fill\_ListView(true, content);
        }
    

    Thanks!

    C# data-structures help question

  • Quick app.config question
    M Megidolaon

    I have a default directory saved in my app.config and also another directory. In the options of my program the user is supposed to be able to change the other directory or restore the default. Yet, that doesn't seem to work properly. At program start (first time) default and other directory have the same value. In the options I use a FolderBrowseDialog and then display the SelectedPath in a textbox. When the user clicks apply/ok the value of said textbox is written into the app.config (presumably). Yet, when opening another form to use that changed directory (I double and triple checked for spelling mistakes), the default directory is still used. I checked the .exe.config and .vshost.exe.config files in the debug folder, yet they, too remain unchanged after changing the directory. But when I read the config value during runtime with config.AppSettings.Settings["elementPath"].Value, the value is the changed one as long as I stay on the same form I changed it on. Why does that happen? Thanks.

    C# question debugging

  • Changing control rectangle color?
    M Megidolaon

    It's not a website, it's a windows forms app. I'm currently changing the backcolor to red and forecolor to white (when you change the text, the color also changes back to normal) but that looks kinda awkward. If possible I'd like to use the more elegant way of just coloring the frame of the textbox/drawing a frame around it. How does the blinking look? It's quite possible that there'd be like 5 textboxes on a form which require input and all of them blinking at the same time would probably weird and confusing. I want a simple, yet obvious visual hint that there is something wrong.

    C# graphics question

  • Changing control rectangle color?
    M Megidolaon

    You know how some website login forms change the color of textboxes you left empty to red? I want to do that in my application. Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red. I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.

    C# graphics question

  • comments?
    M Megidolaon

    Thanks for the feedback. I was a bit lost because I used quite similar commenting as aspdotnetdev, but recently I finished a C++ class and the teacher complained all the time about me not commenting enough. When I say obvious I don't mean obvious in the context, I mean something like

    //checking if strings are ints
    for (int i = 0; i < stringArray.Length; i++)
    {
    bool test = int.TryParse(stringArray[i], out testint)
    }

    I.e. using blatantly obvious methods and basically re-stating their names (said teacher complained about me not doing that). I tend to group larger sections together with regions, like button events, private methods, etc.

    C# css tutorial question discussion
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups