Jump to content

The teaching thread? c#

Hey!

 

My idea for this thread is basically me developing a project, which is something I'm having quite a hard time doing, and when I learn how to do what I need, I'll paste the explanation to what I did along with the code here, so others may come and see how it works, as I haven't found this on the internet. The idea is kinda like trying to start building a house from the roof, but realize you can't and doing each pillar at a time so you can eventually get the roof going, and then adding the walls, as that is, I feel like, the fastest way of learning, causing a need.

 

Inexperienced programmers(like me) feel free to leave any questions about the current code if you don't know what it does. I will comment it in and PM you about the changes :D

 

So, I have this project that is making some sort of an overlay, but I'm going to need a lot of help.

I'm starting off with a form that will change it's opacity based on a key press.

 

I got this so far:

 

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace bigprojectsmile{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        bool isinvis;        private void Form1_KeyUp(object sender, KeyEventArgs e)        {            switch (e.KeyCode)            {                case Keys.F1:                    this.Opacity = 0;                    isinvis = true;                    break;                case Keys.F2:                    this.Opacity = 100;                    isinvis = false;                    break;                default :                    if (isinvis == true)                    {                        MessageBox.Show("Nothing will happen while the form is invisible, please press F2 to make it visible!");                    }                                      break;            }        }    }}

So basically the form will turn invisible when I release F1 and visible when I release F2, along with telling me that no action will be taken while the form is invisible.

The problem now is: I don't know how to read keys from outside the application. I've been reading something about HOOKS but I really still have no idea how it works. After I do this I'll be looking to make that message only show when the form is active.

 

Thank you in advance:D

Link to comment
Share on other sites

Link to post
Share on other sites

Sounds interesting, too bad its not in C++ since thats what I'm currently learning now. Anyway, I wish you luck

Link to comment
Share on other sites

Link to post
Share on other sites

Interesting indeed, what are the next steps you are wanting to take with this project? Also what functionality do you want the end overlay to have?

 

I have done a little c# in the past and I'm actually currently looking for a project that might help my skills so I may just steal your idea and work on it in my own spare time (if I have any). I will also try to help you as much as I can but believe me when I say I am not very good.

Link to comment
Share on other sites

Link to post
Share on other sites

Interesting, I'm curious to see where this will go.

 

Good luck! :)

Link to comment
Share on other sites

Link to post
Share on other sites

Interesting indeed, what are the next steps you are wanting to take with this project? Also what functionality do you want the end overlay to have?

 

I have done a little c# in the past and I'm actually currently looking for a project that might help my skills so I may just steal your idea and work on it in my own spare time (if I have any). I will also try to help you as much as I can but believe me when I say I am not very good.

It's an actually pretty ambitious idea, I was thinking of something kinda like a steam overlay but waaay more complex, with a file browser and a database from a "server" that could be your home PC, an agenda, etc...

Just something with a lot of accessible really useful functionality, I'm not too sure yet, I'll just be very glad whenever I get this overlay rolling, even if there's only a ticking clock on it. CC:

Link to comment
Share on other sites

Link to post
Share on other sites

I'm a C++ guy , can't really help with C# specific stuff.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

What perplexes me is why you are using WinForms and not WPF.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Humm, I use C++ for console programs, C# for Unity, Java for Android and VB.NET for forms but I guess I can help you out with C# if you are having some problems. They are all really alike. I've made programs before that are what you want but in VB.NET where you can store client informations, sell/buy tables and logs saved on your pc and even viewing 3d models (through unity) but using VB.NET to access them.

Link to comment
Share on other sites

Link to post
Share on other sites

What perplexes me is why you are using WinForms and not WPF.

Wow, I didn't really know about it, I'll be looking into it, seems like a good bet :)

I'm using it because I just get myself started with coding and I didn't know any other options.

Can you give me an overview of it? Nothing like an experienced coder's opinion!

Link to comment
Share on other sites

Link to post
Share on other sites

I guess you need something called a 'global hotkey'. A quick google gave me this: http://stackoverflow.com/questions/15413172/capture-a-keyboard-keypress-in-the-background.

 

Just try it out, maybe it will work.

Thanks!!!

So I guess the problem here is that I'm just not good at google :P

I'm be updating this very soon due to your help :D

Link to comment
Share on other sites

Link to post
Share on other sites

I'm a C++ guy , can't really help with C# specific stuff.

Thanks for passing by then :)

Link to comment
Share on other sites

Link to post
Share on other sites

Im a c# developer so just message me if you need help

Sure! I'm now trying to get this background key read going on my own but once I'm done with that, I should be asking for your help pretty soon :D

Link to comment
Share on other sites

Link to post
Share on other sites

Wow, I didn't really know about it, I'll be looking into it, seems like a good bet :)

I'm using it because I just get myself started with coding and I didn't know any other options.

Can you give me an overview of it? Nothing like an experienced coder's opinion!

 

No problem. Windows Presentation Foundation (WPF) is the successor to the now deprecating WinForms technology. It uses DirectX over GDI and attempts to provide a clean way to separate (decouple) the architecture of the user interface to that of the actual business logic.

 

If you are going to take the WPF approach then you will also need to learn (you don't have to but you should or kittens will be killed) the Model VIew ViewModel (MVVM) design pattern. This perfectly complements working with WPF because it greatly facilitates the decoupling of the architectural concerns mentioned above. You have your View (the UI) that knows nothing about the ViewModel (the place where the business logic is implemented) that in tern knows nothing about the Model (the place where you would have the data or compute model for instance). This essentially means that one may simply and easily swap the View out at some point with no impact on the business logic and and vice versa - the same being true for the Model of course. Each layer interacts by way of various abstraction mechanisms such as Data Binding, messages, ViewModel locators, Dependency Injection (DI) and Inversion of Control (IoC) to name a few.

 

There's a bunch of frameworks/tool kits that heavily augment the MVVM pattern making it incredibly simple to work with an implement such as MVVM Light (my personal favourite), PrismCaliburn and a ton of others.

 

Essentially when designing a system you don't really want to have violation of Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion (SOLID) or Atomicity, Consistency, Isolation, Durability (ACID) as is the case when you have implementation detail spilling out into user interface code... this is coupling by way of having the problem solution highly dependent upon the implementation of the UI and vice versa... in software quite frankly, coupling kills.

 

If you want to go a bit further then you could have a think about Test Driven Development (TDD) and Behaviour Driven Development (BDD). TDD is nice when applied to the Ports and Adapters pattern/Hexagonal architecture as it helps prevent test to implementation detail coupling - something to also be very careful about.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Change is scary, you can't make me use WPF! I like my limitations! 

Link to comment
Share on other sites

Link to post
Share on other sites

If anyone wants to know you can use unmanaged code in C#. (Most C++ hooks/events that you will want are unmanaged)

Here's a link to help: https://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx

Yes if it's C++ you will need a C wrapper to work around the name mangling. You then import the C wrapper calls in your C# code.

When I do this I try to make the C wrapper and the mirror image C# interop layer as thin and as dumb as possible.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Yes if it's C++ you will need a C wrapper to work around the name mangling. You then import the C wrapper calls in your C# code.

When I do this I try to make the C wrapper and the mirror image C# interop layer as thin and as dumb as possible.

There's another way to do it? lol

 

I don't think my brain could handle it if I complicated it at all.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×