Sudoku Grid in Unity 5 - c#

I am new to Unity.
I am converting my Sudoku game written in WPF to Unity2D. I converted everything. However I cant achieve 9*9 grid with Buttons as I did in WPF.
In WPF I created 81 buttons with same event. So when it is called I jsut got their position displayed keyboard with only numbers that cell allowed.
Here is what I needed
Here is what I did.
1: I inserted canvas then tried vertical layout(for adding 3 rows) without success
2: Then I tried grid layout with canvas with fixable count column no success
3: grid layout with flexible option still no result.
I also tried via coding using GUI.BOX, and all still the result is not good.
How can I do it?

Do not use GridLayout, it is only for fixed size "icons" - irrelevant here, do not use.
First use VerticalLayoutGroup
include ..
Don't forget you must put a LayoutElement on each of your three items.
Get that working first.
Then, for your MIDDLE item, add a horizontal group and make that work.

Related

C# : problem to arrange my layout dynamically

I'm trying to develop a tablature editor with a specific look, and I'm struggling to display my controls as I want. I think I'm doing it the wrong way so I need your help! I'm working on Visual Sutdio with C# / Winforms.
Ideally, this should look like this : [1]: https://i.stack.imgur.com/B3q5r.png
Basically, this is an A4 sheet on which I display a datagridview with custom borders. As I progressively fill the datagridview, this one should expand: I do that by adding columns dynamically.
The problem is when I reach the right border of the sheet, it should expand on a new line (like a flow layout panel: when there's no more space the control is added on a new line).
I don't manage to do that. If I add more columns to my datagridview, a horizontal scrollbar appears instead of going on a new line. I tried to mix my datagridview with a flowlayoutpanel but I can't make it work.
Have you got any idea on how to do that? Any help would be highly appreciated.
EDIT :
So in my picture, the grid represents the subdivision of the beat (musically speaking). Each beat is divided in 4 subdivisions (=4 columns).
The numbers represent the notes on the instrument, and several notes can be played at the same time (that's why there are sometimes 2 or more notes in the same column). On the contrary, we can also play 0 notes at a given time, that is why some columns are empy. The user write these notes
Consequently, 1 beat = 1 grid of 4 columns * 4 rows (4 notes maximum can be played at the same time).
The horizontal line is just an indication wether the note should be played with the right hand (above the line) or the left hand (below the line). When the user writes the notes, he decides where to write them.
Each time I add a beat, I add 4 columns. So my whole tablature is a grid of 4 rows * X columns (X being a multiple of 4), in which the user writes the notes he wants. My problem is that I would like to "cut" my grid and display it on several lines so that it fits an A4 sheet.

How to make a 10x10 grid of buttons in Unity efficiently

GameObject[] buttonarray = new GameObject[100];
GameObject[] textarray = new GameObject[100];
Initially I was going to individually make 100 text game objects and 100 button game objects.
Then I realized that I can make an array of each. Now I'm stuck since I'm not sure how to add the buttons or text to the array.
I want to make the grid randomize an integer onto the text on the screen and have the user click it that many times until it becomes zero. Once all of them are clicked the user wins.
This is how I was able to make the grid.I made them into panels and each panel with 10 buttons.I'm new to Unity so please let me know if there is a another way I might do this in unity itself.
There is a GridLayout component that you can use:
It works using the UI/Canvas, so it might need a canvas, but you can make a world space canvas with no UI rendering objects and still use it
There is a component you can add to the parent object of the buttons, if none exists create one. The name of the component is escaping me at the moment however it you just search in the component field you should find it with "grid" or "layout".
What it will do is space the elements equally to your liking.

How to control the space between two labels during run time

Im using Visual Studio 2015 Community C#.
I have two labels on a Windows form suppose Label1 and Label2.
These labels will get filled up with user input namely first name and last name.
How to put even space between them so that during runtime the first name doesn't over lap the last name.
AbrahLincoln Abraham Lincoln
(Label1^)(^Label2) (^Label1) (^Label2)
For example: how to make this ^ INTO that >>>>>>>>>>>>^^
Because if I put space in the Form Design before runtime then for other names It will come like this: John(unnecessary space)Doe
Hope you have understood my problem.
Thanks for your time. :D
Controls are located in a form based on coordinates. Luckily for you these controls have properties that tell you the coordinate for the top, left, right, bottom of a control. So you could dynamically move the right label after setting the text.
Label2.Point = new Point(Label1.Right + 5, Y-coord);
An easier way would be to play about with the labels properties in the designer.
You could also try to anchor label1 to the right and label2 to the left. That way you should have a clean middle line, and as the text grows larger it pushes outwards on does not overlap inwards over each other.
However you need an object to anchor to and luckily the SplitContainer works excellent for this.
Also consider setting the autosize property to off and maxing the widths of the labels. Large enough for the string you expect.
Have you considered making it one label?
As in
theOnlyLabel.Text = $"{dataObject.FirstName} {dataObject.LastName}";
or, if you're using textboxes, something like
theOnlyLabel.Text = $"{txtFirstName.Text} {txtLastName.Text}";
Otherwise, I'm afraid, you'd have to realign these two labels every time your first or last name changes.

Chart control: Design messed Up after clearing and re-adding Y-Values

Been struggling with this through out the day. I have three series on a chart that look like this. NOTE: I am using the winforms control.
The values are being added based on calculations from input. I am using this code to add the values to each series.
this.chart1.Series["green"].Points.AddY(greenvalue);
this.chart1.Series["totalsaving"].Points.AddY(totalsavingvalue);
this.chart1.Series["blue"].Points.AddY(bluevalue);
The series properties I have set like this. Green and totalsaving are both set to StackedColumn, blue is set to Column for chart type.
I then have a button to start over which brings the user back to the input area and I am then using this code to clear the series values on the start over click.
chart1.Series["totalsaving"].Points.Clear();
chart1.Series["green"].Points.Clear();
chart1.Series["blue"].Points.Clear();
The same calculation click is being used as above to calculate and populate the series data. The problem is when I click the calculate button to calculate the values after I have cleared them, the total savings, and the green are missing. Just the blue is shown.
Am I doing something wrong with the way I am trying to clear the values so I can re calculate?
OK, from the edits, comments, our chat and the joim.me session enough data has accumulated to answer the question.
You have twisted the display by adding an extra data point to the blue series in the designer.
This point occupies slot 1 but remains invisible as its value = 0.
This pushes the next point in the series to slot 2
After clearing the points it is gone and the display doesn't work anymore.
The disappearing of the two columns probably was caused by hard coded widths.
You have several paths you can follow:
recreating the extra point with value = 0 before adding the real data (not recommended)
not adding the extra point in the first place but forcing each point into its slot by using Points.AddXY instead of Points.AddY with X being the slot.
not clearing the points but updating their values by using the SetValueY method. After all three data points have beend assigned their new values you need to call chart1.Invalidate() to make it show.
Fore easiest styling of all those properties, some of which are deeply burried inside of property strings(!), you may even decide to add and style&polish all three points in the designer and only update their y-values like this:
chart1.Series["green"].SetValueY(greenvalue);
chart1.Series["totalsaving"].SetValueY(totalsavingvalue);
chart1.Series["blue"].SetValueY(bluevalue);
chart1.Invalidate();
The choice is yours, but in any case I recommend setting the proper X values, be it in code or in the desginer..

MS Reports rdlc c# win forms multiple columns

I am trying to create a Report with two columns.
Records should add in as below...
1.Bob 6.Sarch
2.Sue 7.Barrie
3.Adam 8.James
4.Dave 9.Steve
5.Robin 10.Euan
11.Fred
12.Heidi
13.Liz
For the first column (1-5 in this example), a page break should wrap the data to the second column (6-10). After the second column is full (11-13) the the data should page wrap.
The data used to generate the report will have a fixed number of columns. The height and width required for the data will not change.
I am using with C#, WinForms, .net4. I have tried several various approaches with no success. Thus far I have only managed
1.Bob 2.Sue
3.Adam...
Please help or point me in the right direction :-)
Many Thanks
TL;DR ---> This isn't possible with SSRS, afaik.
If I understand correctly, you want to list the items in a data set, that when rendered with a hard page break renderer will render with these requirements:
items are added vertically as long as there's space on the page
a new column of items is started when the first column ran out of space, vertically
a page break is inserted when the second column filled up the vertical space, thus starting a new, first column on a new page
Now, there's only these controls in SSRS:
Textbox
Table, Matrix
Chart
Gauge
List
Image
Subreport
Line, Rectangle
Out of these only the Tablix (Table/Matrix) and List are remotely capable of such a thing, but they can't satisfy your requirements. I'm afraid the answer to your question is that this can't be (easily) done.
The hard way that this may still be possible is perhaps by creating a custom report item and/or by creating a custom rendering extension. But that may be overkill for just wanting to create a nice little list.

Categories