There's a major bug that seems to affect projects at random, and I don't know how to fix it. I don't know if there's even a way to fix it. See, there's this weird thing that VS2019 does where it will suddenly, and without explanation, stop letting me access any kind of menu strips in the Designer. This includes Context Menu strips. With the Context Menus, they show up when I click the icon at the bottom of the Designer, but they're cut off, as if they're being drawn behind everything else. So I can only see the top half of the text of the first item in the menu. Trying to click on it results in the menu immediately disappearing. Regular Menu Strips that are a staple of GUI programs bring problems of their own. They don't vanish, but clicking on them does nothing. It's like they're just pictures of menus that are supposed to be there. They all operate as they should when the program is run, but there's another problem: without the ability to click on or interact with the menus, I can't set the click events using the functionality built into the editor to do so. When I want to add menu items, I have to go into the properties panel, find Collection, and manually set each item. Then, if there are sub menus for any of them, I have to go into the Collection for each of those and repeat the process. Getting them to work with mouse clicks is not impossible. I just go into the .Designer.cs file and hook into the events manually. It's not ideal. It's actually a pain in the REAR PELVIC SPLIT. What makes it worse is that closing VS and restarting does nothing. When I load the project again, the problem remains. Starting new projects does not present this problem, at least for awhile. Menus work... until VS breaks them again. It appears to be something that VS is doing to projects specifically, since it isn't a universal problem. There's some setting or some switch that gets flipped along the way that breaks certain functionality in the loaded project forevermore. Unless there's a way to fix it. That's what I'm really hoping for. I'm hoping someone has encountered this and found a way to repair the problem. Internet search results have suggested running a Clean on the code, which yielded no results at all. Other comments seem to suggest that Microsoft is quite aware that the problem exists and has for some time, but just don't care enough to fix it. I dunno. Please help? This bug is driving me insane. It slows down my workflow and annoys the living daylights out of me. Yes, there ar
SawmillTurtle
Posts
-
Major bug in VS - Menus not displaying -
HackingIn the words of Biff Tannen: "I think you've got the wrong car, McFly."
-
Problems overriding the OnDraw method on ControlsI'm attempting to make an application with a custom GUI. I have several reasons for doing this. I've looked at various documents, but found that this one seemed to be the most directed at what I wanted to do. Others just suggested removing Form borders and using Panels in creative ways to create a custom form. That's all well and good, and I'd actually figured that much out on my own. What I want to do is completely customize the look of the application. This is where things have gone wrong and I'm not sure what I'm doing wrong. I'm using an MDI Form to make sure that all windows stay within the parent form. I then removed all the menus and borders from the parent form, made the background black, and made the entire application full screen. I thought I had the drawing working for the Forms, but it turns out that I was still seeing the original Forms, just colored whatever color I specified. Not good. I need it to not draw the originals. That's the point of overriding, isn't it? Isn't that what that guide to creating custom graphics was about? I've tried everything I can think of. When I override the event on a custom text box like so...
protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); e.Graphics.DrawLine(Pens.Black, new Point(Location.X, Location.Y + Size.Height), new Point(Location.X + Size.Width, Location.Y + Size.Height)); }
...I get the original text box control with a line drawn under it. I thought commenting out the call to base would make it stop displaying the box, but it doesn't. A similar call in a custom combo box that looks like this...
protected override void OnPaint(PaintEventArgs e) { Pen p = new Pen(new SolidBrush(Color.Brown)); Rectangle R = new Rectangle(Location, Size); Region Reg = new Region(R); e.Graphics.Clip = Reg; e.Graphics.Clear(p.Color); e.Graphics.FillRectangle(p.Brush, R); }
...yields no results at all. Absolutely nothing. You can see from this code that I've tried everything from blasting the graphics off the screen (Graphics.Clear) to trying to just draw over them (Graphics.FillRectangle). It's like there's something way back in the inheritance chain that is overruling me. Could that be it, or am I just forget
-
Using A FileStream As A Texture?I'm still learning C# and I have a long way to go. I wanted to dive into MonoGame because tinkering with game design has been a hobby of mine since I started learning QBasic at the age of 14. I don't want to use their Content Pipeline to load content, because I'd like to figure out how to load custom resources as needed. Someone on Stack Overflow commented HERE that they use FileStreams to load textures directly. I set about trying to figure out how to do that, and I've gotten this far:
FileStream fs = new FileStream("stars.jpg", FileMode.Open);
byte[] readString = new byte[fs.Length];
fs.Read(readString, 0, (int)fs.Length);I have no idea if that code even works, because I haven't gotten to a point where running it would yield any visible results. It seems sound, so once I get the file data in the readString array, I need a way to use it as texture data. I tried casting:
object o = (object)readString;
background = (Texture2D)o;I already know that isn't going to work. I don't even need to run it to figure that one out. I read a little in the MonoGame Reference and thought about using Texture2D.SetData as shown HERE, but I'm not sure how to proceed or even if I'm headed in the right direction. The syntax they provide doesn't really clarify anything.
public void SetData(
T[] data
) where T : ValueType, new()There's an array here, but I'm not sure what it's asking for. Can I provide SetData with the byte array?
background.SetData(readString);
Your help would be most appreciated, and it would go a long way towards helping me advance in my learning. Thanks. :) -Turtle
-
how to extract text from text file and store it in a variable using c#I'm going to run with the assumption that you didn't mean to sound as snarky as you did. For future reference, saying "Do me a favor and tell me" is considered bad manners. It would be a good idea to explain what it is you're trying to do and then use "please" and "thank you". I'm going to give you basic instructions for reading from a raw text file. If you're trying to read binary data, this won't help much. 1. You need to start by placing "using System.IO" at the top of your project. 2. You need to declare an instance of StreamReader, open the file and read a line of text using the StreamReader. This is a watered down version of the class I created for my own projects:
using System;
using System.IO;namespace FileOperations
{
public class LoadData
{
StreamReader reader;public void open(string s) { reader=new StreamReader(s); } public string read() { return reader.ReadLine(); } public void close() { reader.Close(); } }
}
The official Microsoft documentation contains excellent instructions and another example. You can find that HERE. I break everything up like I do so that I'm not stuck reading every line in the file at once like in the Microsoft example. I can call the read() function and read one line at a time, or I can use a for or while loop to call it again and again. I can also leave the file open if I need to or close it immediately, depending on my coding needs. I would recommend that if you use this code, you implement a way to check for the end of the file. That would be as simple (as the Microsoft example shows you) as checking to see if the StreamReader returns a null string. Also, since your question shows a bit of inexperience, I feel the need to point out that you should declare a new instance of "LoadData". Here's a simple example:
LoadData ld = new LoadData();
ld.open("myfile.txt");
string readLine=ld.read();
ld.close();You can also simply copy the functions as they are into your existing code and call them without the need of a separate class, but by doing it this way you make this code available across your entire application. And be sure to add your own namespace at the top. Good luck, and happy coding. -Turtle EDIT: It slipped my mind to mention that you don't need to do it through function calls at all if you aren't plannin
-
I Was Incredibly WrongSoooo, I don't know if any of you remember, but I showed up a couple of weeks back and started a discussion here in which I blasted Microsoft and talked about my refusal to use their products whenever possible. Many of you pointed out how I was missing out by ignoring Visual Studio, which you lauded as a superb IDE. Since then I've found that you are all absolutely right. I was initially hesitant to just give in and switch my IDE because people told me I was wrong. Made me seem kinda wishy-washy. What broke the camel's back for me and made me switch from SharpDevelop to VS was SharpDevelop's inability to find one single file. I was attempting to follow the directions found here but ran into trouble as MSBuild kept returning an error of "Cannot find AxImp.exe". AxImp was precisely where it needed to be for the system to find it, there didn't seem to be anything in the PATH variable to cause the problem and, seeing as I've never worked with this type of thing before, I had no idea what this meant or how to fix it. Some suggested editing the registry, some suggested installing the Windows SDK. What I did instead was install Visual Studio. Building under VS returned no AxImp errors, either because it actually knows how to find the necessary file or because the installation itself installed whatever I needed to get things going. So now I had VS and I couldn't very well go back. I mean, I didn't know if the AxImp error would still pop up if I tried to go back to SD, and I didn't feel it was worth the trouble. I had an IDE that was giving me none of the problems that SD did. No offense if anyone here volunteers their time writing SharpDevelop source code, but it really was slowing me down. Here's a question: If you're writing a program visually, drawing buttons and drop down menus and whatnot, what do you expect a visual IDE to do well? I would expect it to do exactly what common sense says: handle the code in the Designer.cs files and keep track of changes. I lost count of the number of times that SD actually wrote those changes incorrectly. There is an ironic multi-line comment in each and every one of those cs files that says:
/// /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. ///
-
RichTextBox control refuses to update to reflect changes.I've been writing this rental property management program for my landlord for awhile now. I decided to rewrite the section which allows for the creation of custom leases from scratch, because it was far beyond saving. It was overly complicated and bloated; it twisted and weaved through a maze of classes and function calls; it relied heavily upon another class library, which was also unnecessary. We all have to learn sometime, yes? Anyway, I've written a simple class with a form to replace it. It has a listbox which is supposed to keep track of individual sections. It has an RTF box for the actual text and a heading box for the title of each section. There are also formatting buttons and a linklabel that opens a Font Select dialog box. The listbox is bound to a datasource, and the datasource is a BindingList made up of the section titles. The problem is that when I have nothing in the listbox and format the text in the RTF control, the formatting appears. Bold text appears when I hit the "B" button, italics show up when I hit the "I" button, and so on. When I use the context menu to add an entry to the datasource, this no longer happens. The formatting stops working. By using tracing and break points, I can see that it seems to be working. When I watch rtfLeaseText.SelectionFont after hitting the "B", for instance, the "Bold" boolean value is set to true. This is not reflected in the text displayed. I can't imagine why this would be. I'll paste the code below. If someone can help, I'd greatly appreciate it. EDIT: Updated code to reflect changes.
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;namespace NewLeaseForm
{
/// /// Description of LeaseClass.
///
public partial class LeaseClass : Form
{
BindingList section=new BindingList();
BindingList heading=new BindingList();
BindingSource bSource=new BindingSource();
public LeaseClass()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
bSource.DataSource=heading;
lbSection.DataSource=bSource;
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void BBoldClick(object sender, EventArgs e)
{
rtfLeaseText.SelectionFont=new Font(rtfLeaseText.SelectionFont,FontStyle.Bold);
}
void BItalicClick(object sender, EventArgs e)
{
rtfLeaseText.SelectionFont=new Fo -
What I've Learned So FarQuote:
You have much fewer choices using apple than you do using Microsoft
I'll give you that. Apple is one of the most dominating, controlling and unreasonable companies I've ever seen. You're going to spend, what, upwards of a thousand dollars (for the sake of brevity, let's say 1200) on an iPhone, yet Apple is going to tell you what you can and can't do with it? Can't download. Can't install unapproved software. Can't do this. Can't do that. And if you try to jailbreak it to open up your options, you risk bricking it and turning it into a 1200 dollar paperweight. If I pay 1200 dollars on something, who are you to tell me what I can and can't do with it? For 1200 dollars, it had better be able to perform oo-mox on me while simultaneously pouring me shots of Kanar and singing "Bohemian Rhapsody" in Klingon (or any other language in which I order it to sing). Apple is definitely the greater of the two evils.
-
What I've Learned So FarTeaching your mom command line syntax (or anyone's mom for that matter) really sounds like a Yabba Dabba Doo time. Reminds me of this time I installed Linux on this cheap Walmart computer I had, which piqued the interest of my cousin. He then insisted that I put it on his MOTHER'S computer, which I did. He lost his taste for it after he found that nothing he wanted to run would run in Linux. His mother wanted to know why she couldn't install and play The Sims. I was NOT about to try and fight with Wine in the hopes of getting the game to run for five to ten minutes (HOPEFULLY) before crashing. Linux came off the computer, Windows went back on, and my aunt and cousin learned why Linux is an operating system for programmers and nerds. It was a colossal waste of time.
-
What I've Learned So FarProtecting users from themselves. It's funny you should mention that. I read somewhere (though I can't remember where off the top of my head) that NTFS actually has the potential to be incredibly secure, but a lot of the security had to be watered down when the two branches of Windows merged and Windows NT/2000 became XP and the successor to-- ugh-- Windows ME. Can't verify the accuracy of that because I don't remember the source, but I CAN give you a more concrete example: Linux. Linux is one of the most secure operating systems available, and for good reason. You can't wipe your nose without the system asking for administrator approval. When Linux became the platform of choice for Android, what happened? It had to be watered down for public consumption so that John Q Everyman wouldn't be inconvenienced by all those tiresome security checks. It seems like the price that the public pays for convenience IS security. The more secure something is, the more it will pester you to verify what you're doing. "Are you sure you want to install 'SUPER_HACKER_VIRUS_APP' from 'Youcannotreallybethisstupid.com?" Why yes. Yes, I do. Oh, no. My computer is on fire.
-
What I've Learned So FarMy dislike of Microsoft comes from many years of opposing their policy of "Do their thinking for them. Microsoft knows best." It's not blind hatred. It's a lifetime of being told that I'm not smart enough. Take the Firewall in Windows 10. I use my own firewall most of the time, but for the longest time (not sure if it still does it anymore), if you turned it off, Windows would remind you that if you leave it off too long "we'll turn it back on for you." Excuse me? I don't want other people doing my thinking for me. I'm capable of setting up my own firewall. I can even tie my own shoes and I can brush my own teeth, too. Know what I mean? As for casting, did I really miss something that was such a monumental foundation stone? Oh dear. Guess I'll need to do some more Googling and figure out how I could make my life easier. Thanks for the advice.
-
What I've Learned So FarI can answer both questions at the same time: My preferred operating system is Linux. Ubuntu, as a matter of fact. However, she wants me to write a computer program, and it has to run on her OS of choice. Trust me, if I had a choice, this computer would be wiped and Linux would be on it. Since it belongs to her, I'm stuck with it. And if I'm writing a program that runs on Windows, what else would I use? I suppose I could use Visual Basic or Visual C++ but-- surprise! -- both Microsoft products.
-
What I've Learned So FarGreetings. This is the first time I've ever posted here, so I supposed introductions are in order. The name is SawmillTurtle. Sawmill because I used to live on a street with that name, and Turtle because my friends used to say I look like Franklin the Turtle. I don't see the resemblance, but it makes for a good screen name. For the past few months, I've been writing a program in C# for my landlord that keeps track of her rental properties, accounting and maintenance issues. It's an all-in-one kind of thing. I've been using SharpDevelop because of my intense hatred for any and all things Microsoft. I actively avoid using anything they make, so that means I don't use Visual Studio. A good alternative, some say, would be MonoDevelop but Microsoft owns that, too. Up until I started on this project, I'd only tinkered with C# while playing with Unity. My IDE of choice was Game Maker because of the ease of use and the speed at which a program can be written using it. You can go ahead and laugh. It's funny. Game Maker is a good tool for learning programming concepts, but once you have it down it is really best to leave it behind you. I thought I could take everything that GM taught me and use it when I made the transition to C#. Keep laughing. It's still pretty funny. What I thought I knew going into this project and what I actually knew are two very different things. I've learned so much over the past few months. Looking back at the early sections of the code is like looking at a car with square wheels. Looking over it, I keep going, "Now why did I do that" and "What in the world was I thinking". One of my biggest mistakes-- and I just figured this one out yesterday-- was creating classes and then creating separate forms for those classes. It never occurred to me to make them one and the same. Take this, for instance: public void edit(BindingList h) { saved=false; int i=-1; HouseholdForm editHousehold; editHousehold=new HouseholdForm(members,householdName,account, rentOverride,overrideAmount, dueDate,gracePeriod,penaltyAmount,penaltyDate); foreach(HouseHold house in h) if (house.householdName==householdName) i=h.IndexOf(house); editHousehold.setHouseholdList(i); editHousehold.ShowDialog(); if(editHousehold.saveMe) { //members.Clear(); members=editHousehold.listOfMembers; householdName=editHousehold.householdName; rentOverride=editHousehold.overridedefaultRent; overrideAmount=editHousehold.oRid